package com.paic.mhis.hcpms.quota.exportword.biz.service.impl;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.paic.mhis.hcpms.common.document.util.Constant;
import com.paic.mhis.hcpms.quota.calculationreport.kpiinterface.biz.service.KpiCoreDataService;
import com.paic.mhis.hcpms.quota.calculationreport.kpiinterface.dto.KpiConditionDTO;
import com.paic.mhis.hcpms.quota.calculationreport.kpiinterface.dto.KpiGradeDTO;
import com.paic.mhis.hcpms.quota.calculationreport.kpiinterface.dto.KpiMedicalOrgDTO;
import com.paic.mhis.hcpms.quota.calculationreport.kpiinterface.dto.KpiSociationDTO;
import com.paic.mhis.hcpms.quota.exportword.biz.service.AutoGetMedicalFeeService;
import com.paic.mhis.hcpms.quota.exportword.utils.GeneralMethods;
import com.paic.mhis.hcpms.quota.exportword.utils.WordReportCalculateHelper;
import com.paic.mhis.hcpms.quota.settlement.common.Constants;
import com.paic.mhis.hcpms.quota.settlement.common.KpiValueConst;

@Service("autoGetMedicalFeeService")
public class AutoGetMedicalFeeServiceImpl implements AutoGetMedicalFeeService {

	@Autowired
	private KpiCoreDataService kpiCoreDataService;

	GeneralMethods generalMethods = GeneralMethods.getInstance();

	private WordReportCalculateHelper helper = WordReportCalculateHelper.getInstance();

	// 第一部分住院药品费用
	@Override
	public Map<String, Object> getHosMedicalFeeToWord(Map<String, Object> paramsMap, Map<String, Object> kpiLimitValue) {
		paramsMap.put("visitType", KpiValueConst.VISIT_HOS);
		paramsMap.put("kpiValue", KpiValueConst.KPI0053);
		Map<String, Object> resultMap = new HashMap<String, Object>();
		resultMap = getHosMedicalKpiInfo(paramsMap, kpiLimitValue);
		return resultMap;
	}

	// GHG住院药品值(总)'0'

	private Map<String, Object> getHosMedicalKpiInfo(Map<String, Object> paramsMap, Map<String, Object> kpiLimitValue) {
		Map<String, Object> resultMap = new HashMap<String, Object>();
		String month = paramsMap.get("currentDate").toString();
		String visitType = paramsMap.get("visitType").toString();
		String regionCode = paramsMap.get("regionCode").toString();
		KpiConditionDTO c = new KpiConditionDTO();
		c.setSociationCode(regionCode);
		List<String> vl = new ArrayList<String>();
		vl.add(KpiValueConst.VISIT_HOS);
		c.setVisitTypeList(vl);
		List<String> kl = new ArrayList<String>();
		kl.add(KpiValueConst.KPI0053);
		c.setKpiCodeList(kl);
		c.setPeriod(KpiValueConst.MONTH);
		c.setKpiTime(month);
		List<KpiSociationDTO> list = kpiCoreDataService.queryKpiBySoc(c);
		if (list.isEmpty()) {
			resultMap.put("k0_2_2_1_Fee_end", "0.00");
			resultMap.put(
					"k0_2_2_1_Fee_health_flag_end",
					helper.checkFlag(helper.checkRation(new BigDecimal(0), new BigDecimal(0),
							setRatioMap("KPI0053", kpiLimitValue))));
			resultMap.put("k0_2_2_1_yoy_flag_end", getAllRatioCompareResult(new BigDecimal(0)));
			resultMap.put("k0_2_2_1_yoy_end", "0.00");
			resultMap.put("k0_2_2_1_yoy_result_end", helper.checkFlag(helper.checkOneRation(new BigDecimal(0),
					setRatioMap("KPI0053", kpiLimitValue), 1)));
			resultMap.put("k0_2_2_1_mom_flag_end", getAllRatioCompareResult(new BigDecimal(0)));
			resultMap.put("k0_2_2_1_mom_end", "0.00");
			resultMap.put("k0_2_2_1_mom_result_end", helper.checkFlag(helper.checkOneRation(new BigDecimal(0),
					setRatioMap("KPI0053", kpiLimitValue), 2)));
			helper.setRatioYoyAndMom(resultMap, kpiLimitValue, "KPI0005", KpiValueConst.KPI0053);
		} else {
			resultMap = conventHosMedicalListToMap(list, month, visitType, kpiLimitValue);
		}
		return resultMap;
	}

	private Map<String, Object> conventHosMedicalListToMap(List<KpiSociationDTO> list, String month, String visitType,
			Map<String, Object> kpiLimitValue) {
		Map<String, Object> resultMap = new HashMap<String, Object>();
		for (KpiSociationDTO ksd : list) {
			if (KpiValueConst.KPI0053.equals(ksd.getKpiCode())) {
				resultMap.put("k0_2_2_1_Fee_end",
						twoDecimals(helper.yuanToTenThousands(helper.filterNullValue(ksd.getKpiValue()))));
				resultMap.put("k0_2_2_1_Fee_cookie_end", helper.filterNullValue(ksd.getKpiValue()));
				resultMap.put("k0_2_2_1_yoy_end", twoDecimals(helper.filterNullValue(ksd.getPeriodRatio())).abs());
				resultMap.put("k0_2_2_1_mom_end", twoDecimals(helper.filterNullValue(ksd.getChainRatio())).abs());
			}
			resultMap.put(
					"k0_2_2_1_Fee_health_flag_end",
					helper.checkRation(helper.filterNullValue(ksd.getPeriodRatio()),
							helper.filterNullValue(ksd.getChainRatio()), setRatioMap("KPI0053", kpiLimitValue)));
			resultMap.put("k0_2_2_1_yoy_flag_end",
					getAllRatioCompareResult(helper.filterNullValue(ksd.getPeriodRatio())));
			resultMap.put(
					"k0_2_2_1_yoy_result_end",
					helper.checkFlag(helper.checkOneRation(helper.filterNullValue(ksd.getPeriodRatio()),
							setRatioMap("KPI0053", kpiLimitValue), 1)));
			resultMap.put("k0_2_2_1_mom_flag_end",
					getAllRatioCompareResult(helper.filterNullValue(ksd.getChainRatio())));
			resultMap.put(
					"k0_2_2_1_mom_result_end",
					helper.checkFlag(helper.checkOneRation(helper.filterNullValue(ksd.getChainRatio()),
							setRatioMap("KPI0053", kpiLimitValue), 2)));
		}
		return helper.setRatioYoyAndMom(resultMap, kpiLimitValue, "KPI0005", KpiValueConst.KPI0053);
	}

	// 第一部分住院其他费用
	@Override
	public Map<String, Object> getHosOthersFeeToWord(Map<String, Object> paramsMap, Map<String, Object> kpiLimitValue) {
		paramsMap.put("visitType", KpiValueConst.VISIT_HOS);
		Map<String, Object> resultMap = new HashMap<String, Object>();
		resultMap = getHosEachKpiInfo(paramsMap, resultMap);
		resultMap = getHosOthersMedDates(paramsMap, kpiLimitValue, resultMap);
		resultMap = getHosCheckFeeToWord(paramsMap, resultMap);
		return resultMap;
	}

	private Map<String, Object> getHosEachKpiInfo(Map<String, Object> paramsMap, Map<String, Object> resultMap) {
		String month = paramsMap.get("currentDate").toString();
		String visitType = paramsMap.get("visitType").toString();
		String regionCode = paramsMap.get("regionCode").toString();
		KpiConditionDTO c = new KpiConditionDTO();
		c.setSociationCode(regionCode);
		List<String> vl = new ArrayList<String>();
		vl.add(KpiValueConst.VISIT_HOS);
		c.setVisitTypeList(vl);
		List<String> kl = new ArrayList<String>();
		kl.add(KpiValueConst.KPI0025);
		kl.add(KpiValueConst.KPI0029);
		kl.add(KpiValueConst.KPI0030);
		kl.add(KpiValueConst.KPI0032);
		kl.add(KpiValueConst.KPI0035);
		kl.add(KpiValueConst.KPI0069);
		c.setKpiCodeList(kl);
		c.setPeriod(KpiValueConst.MONTH);
		c.setKpiTime(month);
		List<KpiSociationDTO> list = kpiCoreDataService.queryKpiBySoc(c);
		if (list.isEmpty()) {
			String[] l1 = { "检 查 费", "0.00", "0.00", "0.00", "0.00" };// 检查费
			String[] l2 = { "治 疗 费", "0.00", "0.00", "0.00", "0.00" };// 治疗费
			String[] l3 = { "手 术 费", "0.00", "0.00", "0.00", "0.00" };// 手术费
			String[] l4 = { "化 验 费", "0.00", "0.00", "0.00", "0.00" };// 化验费
			String[] l5 = { "其 他 费", "0.00", "0.00", "0.00", "0.00" };// 其他费
			String[] l6 = { "其 余 费 用", "0.00", "0.00", "0.00", "0.00" };// 其余费用
			String[] l7 = { "合 计", "0.00", "0.00", "", "" };// 合计
			List<Object> kpiList = new ArrayList<Object>();
			kpiList.add(l1);
			kpiList.add(l2);
			kpiList.add(l3);
			kpiList.add(l4);
			kpiList.add(l5);
			kpiList.add(l6);
			kpiList.add(l7);
			resultMap.put("k0_2_2_2_fee_tableList_end", kpiList);
		} else {
			resultMap = conventHosEveryKpiListToMap(list, month, visitType);
		}
		return resultMap;
	}

	private Map<String, Object> conventHosEveryKpiListToMap(List<KpiSociationDTO> list, String month, String visitType) {
		String[] l1 = { "检 查 费", "0.00", "0.00", "0.00", "0.00" };// 检查费
		String[] l2 = { "治 疗 费", "0.00", "0.00", "0.00", "0.00" };// 治疗费
		String[] l3 = { "手 术 费", "0.00", "0.00", "0.00", "0.00" };// 手术费
		String[] l4 = { "化 验 费", "0.00", "0.00", "0.00", "0.00" };// 化验费
		String[] l5 = { "其 他 费", "0.00", "0.00", "0.00", "0.00" };// 其他费
		String[] l6 = { "其 余 费 用", "0.00", "0.00", "0.00", "0.00" };// 其余费用
		String[] l7 = { "合 计", "0.00", "0.00", "", "" };// 合计
		List<Object> kpiList = new ArrayList<Object>();
		List<Object> kpiFeeList = new ArrayList<Object>();
		String[] exactCheckFee = { "检 查 费", "0.00" };
		String[] exactTreatFee = { "治 疗 费", "0.00" };
		String[] exactOperationFee = { "手 术 费", "0.00" };
		String[] exactAssayFee = { "化 验 费", "0.00" };
		String[] exactOthersFee = { "其 他 费", "0.00" };
		String[] exactTheRestFee = { "其 余 费 用", "0.00" };
		Map<String, Object> resultMap = new HashMap<String, Object>();
		Map<String, BigDecimal> fee = new HashMap<String, BigDecimal>();
		for (KpiSociationDTO kst : list) {
			if (KpiValueConst.KPI0029.equals(kst.getKpiCode())) {
				l1[1] = helper.yuanToTenThousands(kst.getKpiValue()).toString();
				BigDecimal checkFee = kst.getKpiValue();
				fee.put("checkFee", checkFee);
				exactCheckFee[1] = checkFee.toString();
				fee.put("kpi0029Value", new BigDecimal(l1[1]));
				l1[3] = helper.filterNullValue(kst.getPeriodRatio()).setScale(2, BigDecimal.ROUND_HALF_UP).toString();
				l1[4] = helper.filterNullValue(kst.getChainRatio()).setScale(2, BigDecimal.ROUND_HALF_UP).toString();
			}
			if (KpiValueConst.KPI0030.equals(kst.getKpiCode())) {
				l2[1] = helper.yuanToTenThousands(kst.getKpiValue()).toString();
				BigDecimal treatFee = kst.getKpiValue();
				fee.put("treatFee", treatFee);
				exactTreatFee[1] = treatFee.toString();
				fee.put("kpi0030Value", new BigDecimal(l2[1]));
				l2[3] = helper.filterNullValue(kst.getPeriodRatio()).setScale(2, BigDecimal.ROUND_HALF_UP).toString();
				l2[4] = helper.filterNullValue(kst.getChainRatio()).setScale(2, BigDecimal.ROUND_HALF_UP).toString();
			}
			if (KpiValueConst.KPI0025.equals(kst.getKpiCode())) {
				l3[1] = helper.yuanToTenThousands(kst.getKpiValue()).toString();
				BigDecimal operationFee = kst.getKpiValue();
				fee.put("operationFee", operationFee);
				exactOperationFee[1] = operationFee.toString();
				fee.put("kpi0025Value", new BigDecimal(l3[1]));
				l3[3] = helper.filterNullValue(kst.getPeriodRatio()).setScale(2, BigDecimal.ROUND_HALF_UP).toString();
				l3[4] = helper.filterNullValue(kst.getChainRatio()).setScale(2, BigDecimal.ROUND_HALF_UP).toString();
			}
			if (KpiValueConst.KPI0032.equals(kst.getKpiCode())) {
				l4[1] = helper.yuanToTenThousands(kst.getKpiValue()).toString();
				BigDecimal assayFee = kst.getKpiValue();
				fee.put("assayFee", assayFee);
				exactAssayFee[1] = assayFee.toString();
				fee.put("kpi0032Value", new BigDecimal(l4[1]));
				l4[3] = helper.filterNullValue(kst.getPeriodRatio()).setScale(2, BigDecimal.ROUND_HALF_UP).toString();
				l4[4] = helper.filterNullValue(kst.getChainRatio()).setScale(2, BigDecimal.ROUND_HALF_UP).toString();
			}
			if (KpiValueConst.KPI0035.equals(kst.getKpiCode())) {
				l5[1] = helper.yuanToTenThousands(kst.getKpiValue()).toString();
				BigDecimal othersFee = kst.getKpiValue();
				fee.put("othersFee", othersFee);
				exactOthersFee[1] = othersFee.toString();
				fee.put("kpi0035Value", new BigDecimal(l5[1]));
				l5[3] = helper.filterNullValue(kst.getPeriodRatio()).setScale(2, BigDecimal.ROUND_HALF_UP).toString();
				l5[4] = helper.filterNullValue(kst.getChainRatio()).setScale(2, BigDecimal.ROUND_HALF_UP).toString();
			}
			if (KpiValueConst.KPI0069.equals(kst.getKpiCode())) {
				l6[1] = helper.yuanToTenThousands(kst.getKpiValue()).toString();
				BigDecimal theRestFee = kst.getKpiValue();
				fee.put("theRestFee", theRestFee);
				exactTheRestFee[1] = theRestFee.toString();
				fee.put("kpi0069Value", new BigDecimal(l6[1]));
				l6[3] = helper.filterNullValue(kst.getPeriodRatio()).setScale(2, BigDecimal.ROUND_HALF_UP).toString();
				l6[4] = helper.filterNullValue(kst.getChainRatio()).setScale(2, BigDecimal.ROUND_HALF_UP).toString();
			}
		}
		kpiFeeList.add(exactCheckFee);
		kpiFeeList.add(exactTreatFee);
		kpiFeeList.add(exactOperationFee);
		kpiFeeList.add(exactAssayFee);
		kpiFeeList.add(exactOthersFee);
		kpiFeeList.add(exactTheRestFee);
		resultMap.put("k0_2_2_2_fee_pieList_end", kpiFeeList);
		BigDecimal exactTotalFee = helper.filterNullValue(fee.get("checkFee"))
				.add(helper.filterNullValue(fee.get("treatFee"))).add(helper.filterNullValue(fee.get("operationFee")))
				.add(helper.filterNullValue(fee.get("assayFee"))).add(helper.filterNullValue(fee.get("othersFee")))
				.add(helper.filterNullValue(fee.get("theRestFee")));
		BigDecimal total = helper.filterNullValue(fee.get("kpi0029Value"))
				.add(helper.filterNullValue(fee.get("kpi0025Value")))
				.add(helper.filterNullValue(fee.get("kpi0030Value")))
				.add(helper.filterNullValue(fee.get("kpi0032Value")))
				.add(helper.filterNullValue(fee.get("kpi0035Value")))
				.add(helper.filterNullValue(fee.get("kpi0069Value"))).setScale(2, BigDecimal.ROUND_HALF_UP);
		l7[1] = total.toString();
		BigDecimal checkPercent = divideNotNullOrZero(fee.get("checkFee"), exactTotalFee).multiply(new BigDecimal(100))
				.setScale(2, BigDecimal.ROUND_HALF_UP);
		l1[2] = checkPercent.toString();
		BigDecimal treatPercent = divideNotNullOrZero(fee.get("treatFee"), exactTotalFee).multiply(new BigDecimal(100))
				.setScale(2, BigDecimal.ROUND_HALF_UP);
		l2[2] = treatPercent.toString();
		BigDecimal operationPercent = divideNotNullOrZero(fee.get("operationFee"), exactTotalFee).multiply(
				new BigDecimal(100)).setScale(2, BigDecimal.ROUND_HALF_UP);
		l3[2] = operationPercent.toString();
		BigDecimal assayPercent = divideNotNullOrZero(fee.get("assayFee"), exactTotalFee).multiply(new BigDecimal(100))
				.setScale(2, BigDecimal.ROUND_HALF_UP);
		l4[2] = assayPercent.toString();
		BigDecimal exactPercent = divideNotNullOrZero(fee.get("othersFee"), exactTotalFee)
				.multiply(new BigDecimal(100)).setScale(2, BigDecimal.ROUND_HALF_UP);
		l5[2] = exactPercent.toString();
		BigDecimal theRestPercent = divideNotNullOrZero(fee.get("theRestFee"), exactTotalFee).multiply(
				new BigDecimal(100)).setScale(2, BigDecimal.ROUND_HALF_UP);
		l6[2] = theRestPercent.toString();
		l7[2] = "100.00";
		kpiList.add(l1);
		kpiList.add(l2);
		kpiList.add(l3);
		kpiList.add(l4);
		kpiList.add(l5);
		kpiList.add(l6);
		kpiList.add(l7);
		resultMap.put("k0_2_2_2_fee_tableList_end", kpiList);
		return resultMap;
	}

	private Map<String, Object> getHosOthersMedDates(Map<String, Object> paramsMap, Map<String, Object> kpiLimitValue,
			Map<String, Object> resultMap) {
		String month = paramsMap.get("currentDate").toString();
		String visitType = paramsMap.get("visitType").toString();
		String regionCode = paramsMap.get("regionCode").toString();
		KpiConditionDTO c = new KpiConditionDTO();
		c.setSociationCode(regionCode);
		List<String> vl = new ArrayList<String>();
		vl.add(KpiValueConst.VISIT_HOS);
		c.setVisitTypeList(vl);
		List<String> kl = new ArrayList<String>();
		kl.add(KpiValueConst.KPI0070);
		c.setKpiCodeList(kl);
		c.setPeriod(KpiValueConst.MONTH);
		c.setKpiTime(month);
		List<KpiSociationDTO> list = kpiCoreDataService.queryKpiBySoc(c);
		if (list.isEmpty()) {
			resultMap.put("k0_2_2_2_fee_end", "0.00");
			resultMap.put(
					"k0_2_2_2_fee_health_flag_end",
					helper.checkFlag(helper.checkRation(new BigDecimal(0), new BigDecimal(0),
							setRatioMap("KPI0070", kpiLimitValue))));
			resultMap.put("k0_2_2_2_yoy_flag_end", getAllRatioCompareResult(new BigDecimal(0)));
			resultMap.put("k0_2_2_2_yoy_end", "0.00");
			resultMap.put("k0_2_2_2_yoy_result_end", helper.checkFlag(helper.checkOneRation(new BigDecimal(0),
					setRatioMap("KPI0070", kpiLimitValue), 1)));
			resultMap.put("k0_2_2_2_mom_flag_end", getAllRatioCompareResult(new BigDecimal(0)));
			resultMap.put("k0_2_2_2_mom_end", "0.00");
			resultMap.put("k0_2_2_2_mom_result_end", helper.checkFlag(helper.checkOneRation(new BigDecimal(0),
					setRatioMap("KPI0070", kpiLimitValue), 2)));
			helper.setRatioYoyAndMom(resultMap, kpiLimitValue, "KPI0069", KpiValueConst.KPI0070);
		} else {
			resultMap = conventHosOthersFeeList(resultMap, list, month, visitType, kpiLimitValue);
		}
		return resultMap;
	}

	private Map<String, Object> conventHosOthersFeeList(Map<String, Object> resultMap, List<KpiSociationDTO> list,
			String month, String visitType, Map<String, Object> kpiLimitValue) {
		for (KpiSociationDTO ksd : list) {
			if (KpiValueConst.KPI0070.equals(ksd.getKpiCode())) {
				resultMap.put("k0_2_2_2_fee_end",
						twoDecimals(helper.yuanToTenThousands(helper.filterNullValue(ksd.getKpiValue()))));
				resultMap.put(
						"k0_2_2_2_fee_health_flag_end",
						helper.checkRation(helper.filterNullValue(ksd.getPeriodRatio()),
								helper.filterNullValue(ksd.getChainRatio()), setRatioMap("KPI0070", kpiLimitValue)));
				resultMap.put("k0_2_2_2_fee_cookie_end", helper.filterNullValue(ksd.getKpiValue()));
				resultMap.put("k0_2_2_2_yoy_end", twoDecimals(helper.filterNullValue(ksd.getPeriodRatio())).abs());
				resultMap.put("k0_2_2_2_yoy_flag_end",
						getAllRatioCompareResult(helper.filterNullValue(ksd.getPeriodRatio())));
				resultMap.put("k0_2_2_2_yoy_result_end", helper.checkFlag(helper.checkOneRation(
						helper.filterNullValue(ksd.getPeriodRatio()), setRatioMap("KPI0070", kpiLimitValue), 1)));
				resultMap.put("k0_2_2_2_mom_end", twoDecimals(helper.filterNullValue(ksd.getChainRatio())).abs());
				resultMap.put("k0_2_2_2_mom_flag_end",
						getAllRatioCompareResult(helper.filterNullValue(ksd.getChainRatio())));
				resultMap.put("k0_2_2_2_mom_result_end", helper.checkFlag(helper.checkOneRation(
						helper.filterNullValue(ksd.getChainRatio()), setRatioMap("KPI0070", kpiLimitValue), 2)));
			}
		}
		return helper.setRatioYoyAndMom(resultMap, kpiLimitValue, "KPI0069", KpiValueConst.KPI0070);
	}

	private Map<String, Object> getHosCheckFeeToWord(Map<String, Object> paramsMap, Map<String, Object> resultMap) {
		paramsMap.put("visitType", KpiValueConst.VISIT_HOS);
		GeneralMethods.getInstance().addAllValueToMap(getHosCheckKpiInfo(paramsMap), resultMap);
		return resultMap;
	}

	private Map<String, Object> getHosCheckKpiInfo(Map<String, Object> paramsMap) {
		String endMonth = paramsMap.get("currentDate").toString();
		String visitType = paramsMap.get("visitType").toString();
		String regionCode = paramsMap.get("regionCode").toString();
		Map<String, Object> resultMap = new HashMap<String, Object>();
		KpiConditionDTO c = new KpiConditionDTO();
		c.setSociationCode(regionCode);
		List<String> vl = new ArrayList<String>();
		vl.add(KpiValueConst.VISIT_HOS);
		c.setVisitTypeList(vl);
		List<String> kl = new ArrayList<String>();
		c.setKpiCodeList(kl);
		c.setPeriod(KpiValueConst.MONTH);
		String startMonth = helper.getStartDate(endMonth, -Constant.MONTH_THIRTYFIVE);
		c.setKpiTimeStart(startMonth);
		c.setKpiTimeEnd(endMonth);
		kl.add(KpiValueConst.KPI0025);
		List<KpiSociationDTO> dataList = kpiCoreDataService.queryKpiBySoc(c);
		resultMap = conventHosCheckListToMap(KpiValueConst.KPI0025, dataList, startMonth, endMonth, visitType,
				resultMap);
		kl.clear();
		kl.add(KpiValueConst.KPI0029);
		List<KpiSociationDTO> dataList1 = kpiCoreDataService.queryKpiBySoc(c);
		resultMap = conventHosCheckListToMap(KpiValueConst.KPI0029, dataList1, startMonth, endMonth, visitType,
				resultMap);
		kl.clear();
		kl.add(KpiValueConst.KPI0030);
		List<KpiSociationDTO> dataList2 = kpiCoreDataService.queryKpiBySoc(c);
		resultMap = conventHosCheckListToMap(KpiValueConst.KPI0030, dataList2, startMonth, endMonth, visitType,
				resultMap);
		kl.clear();
		kl.add(KpiValueConst.KPI0032);
		List<KpiSociationDTO> dataList3 = kpiCoreDataService.queryKpiBySoc(c);
		resultMap = conventHosCheckListToMap(KpiValueConst.KPI0032, dataList3, startMonth, endMonth, visitType,
				resultMap);
		kl.clear();
		kl.add(KpiValueConst.KPI0035);
		List<KpiSociationDTO> dataList4 = kpiCoreDataService.queryKpiBySoc(c);
		resultMap = conventHosCheckListToMap(KpiValueConst.KPI0035, dataList4, startMonth, endMonth, visitType,
				resultMap);
		kl.clear();
		kl.add(KpiValueConst.KPI0069);
		List<KpiSociationDTO> dataList5 = kpiCoreDataService.queryKpiBySoc(c);
		resultMap = conventHosCheckListToMap(KpiValueConst.KPI0069, dataList5, startMonth, endMonth, visitType,
				resultMap);
		return resultMap;
	}

	@SuppressWarnings("unchecked")
	private Map<String, Object> conventHosCheckListToMap(String kpiCode, List<KpiSociationDTO> dataList,
			String startMonth, String endMonth, String visitType, Map<String, Object> resultMap) {
		Map<String, Object> dataMap = getCheckCalculateDataMap(kpiCode, dataList, visitType, startMonth, endMonth);
		// // 将查询数据封装到List
		List<BigDecimal> periodList = (List<BigDecimal>) dataMap.get("periodList_end");
		List<BigDecimal> chainList = (List<BigDecimal>) dataMap.get("chainList_end");
		// // 总额
		List<BigDecimal> totalList = (List<BigDecimal>) dataMap.get("totalList_end");

		Map<String, Object> avgDataMap = getAvgData(periodList, chainList, totalList);

		// // 同期平均值计算
		List<BigDecimal> avgList = (List<BigDecimal>) avgDataMap.get("avgList");
		List<BigDecimal> RecentOneYear = helper.createSetListValue(Constant.MONTH_TWELVE, new BigDecimal(0));
		List<BigDecimal> periodLine = helper.createSetListValue(Constant.MONTH_TWELVE, new BigDecimal(0));
		List<BigDecimal> chainLine = helper.createSetListValue(Constant.MONTH_TWELVE, new BigDecimal(0));
		for (int i = 0; i < Constant.MONTH_TWELVE; i++) {
			RecentOneYear.set(i, helper.filterNullValue(totalList.get(totalList.size() + i - Constant.MONTH_TWELVE)));
			periodLine.set(i, helper.filterNullValue(periodList.get(periodList.size() + i - Constant.MONTH_TWELVE)));
			chainLine.set(i, helper.filterNullValue(chainList.get(chainList.size() + i - Constant.MONTH_TWELVE)));
		}
		if (KpiValueConst.KPI0025.equals(kpiCode)) {
			resultMap.put("k0_2_2_25_fee_gqynList_end", helper.toFixedUniqueOrgList(RecentOneYear));
			resultMap.put("k0_2_2_25_fee_gqsnList_end", helper.toFixedUniqueOrgList(avgList));
			resultMap.put("k0_2_2_25_fee_yoyList_end", helper.toFixedPercentList(periodLine));
			resultMap.put("k0_2_2_25_fee_momList_end", helper.toFixedPercentList(chainLine));
		}
		if (KpiValueConst.KPI0029.equals(kpiCode)) {
			resultMap.put("k0_2_2_2_fee_gqynList_end", helper.toFixedUniqueOrgList(RecentOneYear));
			resultMap.put("k0_2_2_2_fee_gqsnList_end", helper.toFixedUniqueOrgList(avgList));
			resultMap.put("k0_2_2_2_fee_yoyList_end", helper.toFixedPercentList(periodLine));
			resultMap.put("k0_2_2_2_fee_momList_end", helper.toFixedPercentList(chainLine));
		}
		if (KpiValueConst.KPI0030.equals(kpiCode)) {
			resultMap.put("k0_2_2_30_fee_gqynList_end", helper.toFixedUniqueOrgList(RecentOneYear));
			resultMap.put("k0_2_2_30_fee_gqsnList_end", helper.toFixedUniqueOrgList(avgList));
			resultMap.put("k0_2_2_30_fee_yoyList_end", helper.toFixedPercentList(periodLine));
			resultMap.put("k0_2_2_30_fee_momList_end", helper.toFixedPercentList(chainLine));
		}
		if (KpiValueConst.KPI0032.equals(kpiCode)) {
			resultMap.put("k0_2_2_32_fee_gqynList_end", helper.toFixedUniqueOrgList(RecentOneYear));
			resultMap.put("k0_2_2_32_fee_gqsnList_end", helper.toFixedUniqueOrgList(avgList));
			resultMap.put("k0_2_2_32_fee_yoyList_end", helper.toFixedPercentList(periodLine));
			resultMap.put("k0_2_2_32_fee_momList_end", helper.toFixedPercentList(chainLine));
		}
		if (KpiValueConst.KPI0035.equals(kpiCode)) {
			resultMap.put("k0_2_2_35_fee_gqynList_end", helper.toFixedUniqueOrgList(RecentOneYear));
			resultMap.put("k0_2_2_35_fee_gqsnList_end", helper.toFixedUniqueOrgList(avgList));
			resultMap.put("k0_2_2_35_fee_yoyList_end", helper.toFixedPercentList(periodLine));
			resultMap.put("k0_2_2_35_fee_momList_end", helper.toFixedPercentList(chainLine));
		}
		if (KpiValueConst.KPI0069.equals(kpiCode)) {
			resultMap.put("k0_2_2_69_fee_gqynList_end", helper.toFixedUniqueOrgList(RecentOneYear));
			resultMap.put("k0_2_2_69_fee_gqsnList_end", helper.toFixedUniqueOrgList(avgList));
			resultMap.put("k0_2_2_69_fee_yoyList_end", helper.toFixedPercentList(periodLine));
			resultMap.put("k0_2_2_69_fee_momList_end", helper.toFixedPercentList(chainLine));
		}
		return resultMap;
	}

	private Map<String, Object> getCheckCalculateDataMap(String kpiCode, List<KpiSociationDTO> dataList,
			String visitType, String startMonth, String endMonth) {
		Map<String, Object> CalculateDataMap = new HashMap<String, Object>();
		String kpiTime = "";
		BigDecimal kpiValue = null;
		BigDecimal periodRatio = null;// 同比
		BigDecimal chainRatio = null;// 环比
		// // 将查询数据封装到List
		Map<String, Integer> orderMap = helper.createOrderList(startMonth, endMonth);
		List<BigDecimal> periodList = helper.createSetListValue(orderMap.size(), new BigDecimal(0));
		List<BigDecimal> chainList = helper.createSetListValue(orderMap.size(), new BigDecimal(0));
		// // 总额
		List<BigDecimal> totalList = helper.createSetListValue(orderMap.size(), new BigDecimal(0));

		for (KpiSociationDTO KpiSociationDTO : dataList) {
			kpiCode = KpiSociationDTO.getKpiCode();
			kpiValue = KpiSociationDTO.getKpiValue();
			periodRatio = KpiSociationDTO.getPeriodRatio();
			chainRatio = KpiSociationDTO.getChainRatio();
			kpiTime = GeneralMethods.getInstance().replacTimeFormate(KpiSociationDTO.getKpiTime());
			if (KpiValueConst.KPI0025.equals(kpiCode)) {
				if (KpiSociationDTO.getVisitType().equals(visitType)) {
					periodList.set(orderMap.get(kpiTime), helper.filterNullValue(periodRatio));
					chainList.set(orderMap.get(kpiTime), helper.filterNullValue(chainRatio));
					totalList.set(orderMap.get(kpiTime), helper.filterNullValue(kpiValue));
				}
			}
			if (KpiValueConst.KPI0029.equals(kpiCode)) {
				if (KpiSociationDTO.getVisitType().equals(visitType)) {
					periodList.set(orderMap.get(kpiTime), helper.filterNullValue(periodRatio));
					chainList.set(orderMap.get(kpiTime), helper.filterNullValue(chainRatio));
					totalList.set(orderMap.get(kpiTime), helper.filterNullValue(kpiValue));
				}
			}
			if (KpiValueConst.KPI0030.equals(kpiCode)) {
				if (KpiSociationDTO.getVisitType().equals(visitType)) {
					periodList.set(orderMap.get(kpiTime), helper.filterNullValue(periodRatio));
					chainList.set(orderMap.get(kpiTime), helper.filterNullValue(chainRatio));
					totalList.set(orderMap.get(kpiTime), helper.filterNullValue(kpiValue));
				}
			}
			if (KpiValueConst.KPI0032.equals(kpiCode)) {
				if (KpiSociationDTO.getVisitType().equals(visitType)) {
					periodList.set(orderMap.get(kpiTime), helper.filterNullValue(periodRatio));
					chainList.set(orderMap.get(kpiTime), helper.filterNullValue(chainRatio));
					totalList.set(orderMap.get(kpiTime), helper.filterNullValue(kpiValue));
				}
			}
			if (KpiValueConst.KPI0035.equals(kpiCode)) {
				if (KpiSociationDTO.getVisitType().equals(visitType)) {
					periodList.set(orderMap.get(kpiTime), helper.filterNullValue(periodRatio));
					chainList.set(orderMap.get(kpiTime), helper.filterNullValue(chainRatio));
					totalList.set(orderMap.get(kpiTime), helper.filterNullValue(kpiValue));
				}
			}
			if (KpiValueConst.KPI0069.equals(kpiCode)) {
				if (KpiSociationDTO.getVisitType().equals(visitType)) {
					periodList.set(orderMap.get(kpiTime), helper.filterNullValue(periodRatio));
					chainList.set(orderMap.get(kpiTime), helper.filterNullValue(chainRatio));
					totalList.set(orderMap.get(kpiTime), helper.filterNullValue(kpiValue));
				}
			}
		}
		CalculateDataMap.put("orderMap", orderMap);
		CalculateDataMap.put("periodList_end", periodList);
		CalculateDataMap.put("chainList_end", chainList);
		CalculateDataMap.put("totalList_end", totalList);
		return CalculateDataMap;
	}

	private Map<String, Object> getAvgData(List<BigDecimal> periodList, List<BigDecimal> chainList,
			List<BigDecimal> totalList) {
		Map<String, Object> avgDataMap = new HashMap<String, Object>();
		// 同期平均
		List<BigDecimal> avgList = helper.createSetListValue(Constant.MONTH_TWELVE, new BigDecimal(0));
		List<BigDecimal> avgPeriodList = helper.createSetListValue(Constant.MONTH_TWELVE, new BigDecimal(0));
		List<BigDecimal> avgChainList = helper.createSetListValue(Constant.MONTH_TWELVE, new BigDecimal(0));
		// 计算同期平均值
		for (int i = 0; i < Constant.MONTH_TWELVE; i++) {
			if (totalList != null) {
				avgList.set(i, totalList.get(i).add(totalList.get(i + Constant.MONTH_TWELVE))
						.add(totalList.get(i + 24)).divide(new BigDecimal(3), 2, BigDecimal.ROUND_HALF_UP));
			}
			if (periodList != null) {
				avgPeriodList.set(i,
						periodList.get(i).add(periodList.get(i + Constant.MONTH_TWELVE)).add(periodList.get(i + 24))
								.divide(new BigDecimal(3), 2, BigDecimal.ROUND_HALF_UP));
			}
			if (chainList != null) {
				avgChainList.set(i,
						chainList.get(i).add(chainList.get(i + Constant.MONTH_TWELVE)).add(chainList.get(i + 24))
								.divide(new BigDecimal(3), 2, BigDecimal.ROUND_HALF_UP));
			}
		}
		avgDataMap.put("avgList", avgList);
		avgDataMap.put("avgPeriodList", avgPeriodList);
		avgDataMap.put("avgChainList", avgChainList);
		return avgDataMap;
	}

	@Override
	public Map<String, Object> getOutMedicalFeeToWord(Map<String, Object> paramsMap, Map<String, Object> kpiLimitValue) {
		paramsMap.put("visitType", KpiValueConst.VISIT_OUT);
		paramsMap.put("kpiValue", KpiValueConst.KPI0053);
		Map<String, Object> resultMap = new HashMap<String, Object>();
		resultMap = getOutMedicalKpiInfo(paramsMap, kpiLimitValue);
		return resultMap;
	}

	// GHG门诊药品值(总)'0'
	private Map<String, Object> getOutMedicalKpiInfo(Map<String, Object> paramsMap, Map<String, Object> kpiLimitValue) {
		Map<String, Object> resultMap = new HashMap<String, Object>();
		String month = paramsMap.get("currentDate").toString();
		String visitType = paramsMap.get("visitType").toString();
		String regionCode = paramsMap.get("regionCode").toString();
		KpiConditionDTO c = new KpiConditionDTO();
		c.setSociationCode(regionCode);
		List<String> vl = new ArrayList<String>();
		vl.add(KpiValueConst.VISIT_OUT);
		c.setVisitTypeList(vl);
		List<String> kl = new ArrayList<String>();
		kl.add(KpiValueConst.KPI0053);
		c.setKpiCodeList(kl);
		c.setPeriod(KpiValueConst.MONTH);
		c.setKpiTime(month);
		List<KpiSociationDTO> list = kpiCoreDataService.queryKpiBySoc(c);
		if (list.isEmpty()) {
			resultMap.put("k0_3_2_1_fee_end", "0.00");
			resultMap.put("k0_3_2_1_fee_health_flag_end",
					helper.checkRation(new BigDecimal(0), new BigDecimal(0), setRatioMap("KPI0053", kpiLimitValue)));
			resultMap.put("k0_3_2_1_yoy_flag_end", getAllRatioCompareResult(new BigDecimal(0)));
			resultMap.put("k0_3_2_1_yoy_end", "0.00");
			resultMap.put("k0_3_2_1_yoy_result_end",
					helper.checkOneRation(new BigDecimal(0), setRatioMap("KPI0053", kpiLimitValue), 1));
			resultMap.put("k0_3_2_1_mom_flag_end", getAllRatioCompareResult(new BigDecimal(0)));
			resultMap.put("k0_3_2_1_mom_end", "0.00");
			resultMap.put("k0_3_2_1_mom_result_end",
					helper.checkOneRation(new BigDecimal(0), setRatioMap("KPI0053", kpiLimitValue), 2));

			helper.setRatioYoyAndMom(resultMap, kpiLimitValue, "KPI0005", KpiValueConst.KPI0053);
		} else {
			resultMap = conventOutMedicalListToMap(list, month, visitType, kpiLimitValue);
		}
		return resultMap;
	}

	private Map<String, Object> conventOutMedicalListToMap(List<KpiSociationDTO> list, String month, String visitType,
			Map<String, Object> kpiLimitValue) {
		Map<String, Object> result = new HashMap<String, Object>();
		for (KpiSociationDTO ksd : list) {
			if (KpiValueConst.KPI0053.equals(ksd.getKpiCode())) {
				result.put("k0_3_2_1_yoy_end", twoDecimals(helper.filterNullValue(ksd.getPeriodRatio())).abs());
				result.put("k0_3_2_1_mom_end", twoDecimals(helper.filterNullValue(ksd.getChainRatio())).abs());
				result.put("k0_3_2_1_fee_end",
						twoDecimals(helper.yuanToTenThousands(helper.filterNullValue(ksd.getKpiValue()))));
				result.put("k0_3_2_1_fee_cookie_end", helper.filterNullValue(ksd.getKpiValue()));
			}
			result.put(
					"k0_3_2_1_fee_health_flag_end",
					helper.checkRation(helper.filterNullValue(ksd.getPeriodRatio()),
							helper.filterNullValue(ksd.getChainRatio()), setRatioMap("KPI0053", kpiLimitValue)));
			result.put("k0_3_2_1_yoy_flag_end", getAllRatioCompareResult(helper.filterNullValue(ksd.getPeriodRatio())));
			result.put(
					"k0_3_2_1_yoy_result_end",
					helper.checkFlag(helper.checkOneRation(helper.filterNullValue(ksd.getPeriodRatio()),
							setRatioMap("KPI0053", kpiLimitValue), 1)));
			result.put("k0_3_2_1_mom_flag_end", getAllRatioCompareResult(helper.filterNullValue(ksd.getChainRatio())));
			result.put(
					"k0_3_2_1_mom_result_end",
					helper.checkFlag(helper.checkOneRation(helper.filterNullValue(ksd.getChainRatio()),
							setRatioMap("KPI0053", kpiLimitValue), 2)));
		}
		return helper.setRatioYoyAndMom(result, kpiLimitValue, "KPI0005", KpiValueConst.KPI0053);
	}

	private BigDecimal twoDecimals(BigDecimal ratio) {
		return ratio.divide(new BigDecimal(1), 2, BigDecimal.ROUND_HALF_UP);
	}

	@Override
	public Map<String, Object> getOutOthersFeeToWord(Map<String, Object> paramsMap, Map<String, Object> kpiLimitValue) {
		paramsMap.put("visitType", KpiValueConst.VISIT_OUT);
		paramsMap.put("kpiValue", KpiValueConst.KPI0053);
		paramsMap.put("kpiValue", KpiValueConst.KPI0070);
		Map<String, Object> resultMap = new HashMap<String, Object>();
		resultMap = getOutEachKpiInfo(paramsMap, resultMap);
		resultMap = getOutOthersMedDates(paramsMap, kpiLimitValue, resultMap);
		resultMap = getOutCheckFeeToWord(paramsMap, resultMap);
		return resultMap;
	}

	// 门诊各项指标List '0'
	private Map<String, Object> getOutEachKpiInfo(Map<String, Object> paramsMap, Map<String, Object> resultMap) {
		String month = paramsMap.get("currentDate").toString();
		String visitType = paramsMap.get("visitType").toString();
		String regionCode = paramsMap.get("regionCode").toString();
		KpiConditionDTO c = new KpiConditionDTO();
		c.setSociationCode(regionCode);
		List<String> vl = new ArrayList<String>();
		vl.add(KpiValueConst.VISIT_OUT);
		c.setVisitTypeList(vl);
		List<String> kl = new ArrayList<String>();
		kl.add(KpiValueConst.KPI0025);
		kl.add(KpiValueConst.KPI0029);
		kl.add(KpiValueConst.KPI0030);
		kl.add(KpiValueConst.KPI0032);
		kl.add(KpiValueConst.KPI0035);
		kl.add(KpiValueConst.KPI0069);
		c.setKpiCodeList(kl);
		c.setPeriod(KpiValueConst.MONTH);
		c.setKpiTime(month);
		List<KpiSociationDTO> list = kpiCoreDataService.queryKpiBySoc(c);
		if (list.isEmpty()) {
			String[] l1 = { "检 查 费", "0.00", "0.00", "0.00", "0.00" };// 检查费
			String[] l2 = { "治 疗 费", "0.00", "0.00", "0.00", "0.00" };// 治疗费
			String[] l3 = { "手 术 费", "0.00", "0.00", "0.00", "0.00" };// 手术费
			String[] l4 = { "化 验 费", "0.00", "0.00", "0.00", "0.00" };// 化验费
			String[] l5 = { "其 他 费", "0.00", "0.00", "0.00", "0.00" };// 其他费
			String[] l6 = { "其 余 费 用", "0.00", "0.00", "0.00", "0.00" };// 其余费用
			String[] l7 = { "合 计", "0.00", "0.00", "", "" };// 合计
			List<Object> kpiList = new ArrayList<Object>();
			kpiList.add(l1);
			kpiList.add(l2);
			kpiList.add(l3);
			kpiList.add(l4);
			kpiList.add(l5);
			kpiList.add(l6);
			kpiList.add(l7);
			resultMap.put("k0_3_2_2_fee_tableList_end", kpiList);
		} else {
			resultMap = conventOutEveryKpiListToMap(list, month, visitType);
		}
		return resultMap;
	}

	private Map<String, Object> conventOutEveryKpiListToMap(List<KpiSociationDTO> list, String month, String visitType) {
		String[] l1 = { "检 查 费", "0.00", "0.00", "0.00", "0.00" };// 检查费
		String[] l2 = { "治 疗 费", "0.00", "0.00", "0.00", "0.00" };// 治疗费
		String[] l3 = { "手 术 费", "0.00", "0.00", "0.00", "0.00" };// 手术费
		String[] l4 = { "化 验 费", "0.00", "0.00", "0.00", "0.00" };// 化验费
		String[] l5 = { "其 他 费", "0.00", "0.00", "0.00", "0.00" };// 其他费
		String[] l6 = { "其 余 费 用", "0.00", "0.00", "0.00", "0.00" };// 其余费用
		String[] l7 = { "合 计", "0.00", "0.00", "", "" };// 合计
		List<Object> kpiList = new ArrayList<Object>();
		List<Object> kpiFeeList = new ArrayList<Object>();
		String[] exactCheckFee = { "检 查 费", "0.00" };
		String[] exactTreatFee = { "治 疗 费", "0.00" };
		String[] exactOperationFee = { "手 术 费", "0.00" };
		String[] exactAssayFee = { "化 验 费", "0.00" };
		String[] exactOthersFee = { "其 他 费", "0.00" };
		String[] exactTheRestFee = { "其 余 费 用", "0.00" };
		Map<String, Object> resultMap = new HashMap<String, Object>();
		Map<String, BigDecimal> fee = new HashMap<String, BigDecimal>();
		for (KpiSociationDTO kst : list) {
			if (KpiValueConst.KPI0029.equals(kst.getKpiCode())) {
				l1[1] = helper.yuanToTenThousands(kst.getKpiValue()).toString();
				BigDecimal checkFee = kst.getKpiValue();
				fee.put("checkFee", checkFee);
				exactCheckFee[1] = checkFee.toString();
				fee.put("kpi0029Value", new BigDecimal(l1[1]));
				l1[3] = helper.filterNullValue(kst.getPeriodRatio()).setScale(2, BigDecimal.ROUND_HALF_UP).toString();
				l1[4] = helper.filterNullValue(kst.getChainRatio()).setScale(2, BigDecimal.ROUND_HALF_UP).toString();
			}
			if (KpiValueConst.KPI0030.equals(kst.getKpiCode())) {
				l2[1] = helper.yuanToTenThousands(kst.getKpiValue()).toString();
				BigDecimal treatFee = kst.getKpiValue();
				fee.put("treatFee", treatFee);
				exactTreatFee[1] = treatFee.toString();
				fee.put("kpi0030Value", new BigDecimal(l2[1]));
				l2[3] = helper.filterNullValue(kst.getPeriodRatio()).setScale(2, BigDecimal.ROUND_HALF_UP).toString();
				l2[4] = helper.filterNullValue(kst.getChainRatio()).setScale(2, BigDecimal.ROUND_HALF_UP).toString();
			}
			if (KpiValueConst.KPI0025.equals(kst.getKpiCode())) {
				l3[1] = helper.yuanToTenThousands(kst.getKpiValue()).toString();
				BigDecimal operationFee = kst.getKpiValue();
				fee.put("operationFee", operationFee);
				exactOperationFee[1] = operationFee.toString();
				fee.put("kpi0025Value", new BigDecimal(l3[1]));
				l3[3] = helper.filterNullValue(kst.getPeriodRatio()).setScale(2, BigDecimal.ROUND_HALF_UP).toString();
				l3[4] = helper.filterNullValue(kst.getChainRatio()).setScale(2, BigDecimal.ROUND_HALF_UP).toString();
			}
			if (KpiValueConst.KPI0032.equals(kst.getKpiCode())) {
				l4[1] = helper.yuanToTenThousands(kst.getKpiValue()).toString();
				BigDecimal assayFee = kst.getKpiValue();
				fee.put("assayFee", assayFee);
				exactAssayFee[1] = assayFee.toString();
				fee.put("kpi0032Value", new BigDecimal(l4[1]));
				l4[3] = helper.filterNullValue(kst.getPeriodRatio()).setScale(2, BigDecimal.ROUND_HALF_UP).toString();
				l4[4] = helper.filterNullValue(kst.getChainRatio()).setScale(2, BigDecimal.ROUND_HALF_UP).toString();
			}
			if (KpiValueConst.KPI0035.equals(kst.getKpiCode())) {
				l5[1] = helper.yuanToTenThousands(kst.getKpiValue()).toString();
				BigDecimal othersFee = kst.getKpiValue();
				fee.put("othersFee", othersFee);
				exactOthersFee[1] = othersFee.toString();
				fee.put("kpi0035Value", new BigDecimal(l5[1]));
				l5[3] = helper.filterNullValue(kst.getPeriodRatio()).setScale(2, BigDecimal.ROUND_HALF_UP).toString();
				l5[4] = helper.filterNullValue(kst.getChainRatio()).setScale(2, BigDecimal.ROUND_HALF_UP).toString();
			}
			if (KpiValueConst.KPI0069.equals(kst.getKpiCode())) {
				l6[1] = helper.yuanToTenThousands(kst.getKpiValue()).toString();
				BigDecimal theRestFee = kst.getKpiValue();
				fee.put("theRestFee", theRestFee);
				exactTheRestFee[1] = theRestFee.toString();
				fee.put("kpi0069Value", new BigDecimal(l6[1]));
				l6[3] = helper.filterNullValue(kst.getPeriodRatio()).setScale(2, BigDecimal.ROUND_HALF_UP).toString();
				l6[4] = helper.filterNullValue(kst.getChainRatio()).setScale(2, BigDecimal.ROUND_HALF_UP).toString();
			}
		}
		kpiFeeList.add(exactCheckFee);
		kpiFeeList.add(exactTreatFee);
		kpiFeeList.add(exactOperationFee);
		kpiFeeList.add(exactAssayFee);
		kpiFeeList.add(exactOthersFee);
		kpiFeeList.add(exactTheRestFee);
		resultMap.put("k0_3_2_2_fee_pieList_end", kpiFeeList);
		BigDecimal exactTotalFee = helper.filterNullValue(fee.get("checkFee"))
				.add(helper.filterNullValue(fee.get("treatFee"))).add(helper.filterNullValue(fee.get("operationFee")))
				.add(helper.filterNullValue(fee.get("assayFee"))).add(helper.filterNullValue(fee.get("othersFee")))
				.add(helper.filterNullValue(fee.get("theRestFee")));
		BigDecimal total = helper.filterNullValue(fee.get("kpi0029Value"))
				.add(helper.filterNullValue(fee.get("kpi0025Value")))
				.add(helper.filterNullValue(fee.get("kpi0030Value")))
				.add(helper.filterNullValue(fee.get("kpi0032Value")))
				.add(helper.filterNullValue(fee.get("kpi0035Value")))
				.add(helper.filterNullValue(fee.get("kpi0069Value"))).setScale(2, BigDecimal.ROUND_HALF_UP);
		l7[1] = total.toString();
		BigDecimal checkPercent = divideNotNullOrZero(fee.get("checkFee"), exactTotalFee).multiply(new BigDecimal(100))
				.setScale(2, BigDecimal.ROUND_HALF_UP);
		l1[2] = checkPercent.toString();
		BigDecimal treatPercent = divideNotNullOrZero(fee.get("treatFee"), exactTotalFee).multiply(new BigDecimal(100))
				.setScale(2, BigDecimal.ROUND_HALF_UP);
		l2[2] = treatPercent.toString();
		BigDecimal operationPercent = divideNotNullOrZero(fee.get("operationFee"), exactTotalFee).multiply(
				new BigDecimal(100)).setScale(2, BigDecimal.ROUND_HALF_UP);
		l3[2] = operationPercent.toString();
		BigDecimal assayPercent = divideNotNullOrZero(fee.get("assayFee"), exactTotalFee).multiply(new BigDecimal(100))
				.setScale(2, BigDecimal.ROUND_HALF_UP);
		l4[2] = assayPercent.toString();
		BigDecimal exactPercent = divideNotNullOrZero(fee.get("othersFee"), exactTotalFee)
				.multiply(new BigDecimal(100)).setScale(2, BigDecimal.ROUND_HALF_UP);
		l5[2] = exactPercent.toString();
		BigDecimal theRestPercent = divideNotNullOrZero(fee.get("theRestFee"), exactTotalFee).multiply(
				new BigDecimal(100)).setScale(2, BigDecimal.ROUND_HALF_UP);
		l6[2] = theRestPercent.toString();
		l7[2] = "100.00";
		kpiList.add(l1);
		kpiList.add(l2);
		kpiList.add(l3);
		kpiList.add(l4);
		kpiList.add(l5);
		kpiList.add(l6);
		kpiList.add(l7);
		resultMap.put("k0_3_2_2_fee_tableList_end", kpiList);
		return resultMap;
	}

	private Map<String, Object> getOutOthersMedDates(Map<String, Object> paramsMap, Map<String, Object> kpiLimitValue,
			Map<String, Object> resultMap) {
		String month = paramsMap.get("currentDate").toString();
		String visitType = paramsMap.get("visitType").toString();
		String regionCode = paramsMap.get("regionCode").toString();
		KpiConditionDTO c = new KpiConditionDTO();
		c.setSociationCode(regionCode);
		List<String> vl = new ArrayList<String>();
		vl.add(KpiValueConst.VISIT_OUT);
		c.setVisitTypeList(vl);
		List<String> kl = new ArrayList<String>();
		kl.add(KpiValueConst.KPI0070);
		c.setKpiCodeList(kl);
		c.setPeriod(KpiValueConst.MONTH);
		c.setKpiTime(month);
		List<KpiSociationDTO> list = kpiCoreDataService.queryKpiBySoc(c);
		if (list.isEmpty()) {
			resultMap.put("k0_3_2_2_fee_end", "0.00");
			resultMap.put(
					"k0_3_2_2_health_flag_end",
					helper.checkFlag(helper.checkRation(new BigDecimal(0), new BigDecimal(0),
							setRatioMap("KPI0070", kpiLimitValue))));
			resultMap.put("k0_3_2_2_yoy_flag_end", getAllRatioCompareResult(new BigDecimal(0)));
			resultMap.put("k0_3_2_2_yoy_end", "0.00");
			resultMap.put("k0_3_2_2_yoy_result_end", helper.checkFlag(helper.checkOneRation(new BigDecimal(0),
					setRatioMap("KPI0070", kpiLimitValue), 1)));
			resultMap.put("k0_3_2_2_mom_flag_end", getAllRatioCompareResult(new BigDecimal(0)));
			resultMap.put("k0_3_2_2_mom_end", "0.00");
			resultMap.put("k0_3_2_2_mom_result_end", helper.checkFlag(helper.checkOneRation(new BigDecimal(0),
					setRatioMap("KPI0070", kpiLimitValue), 2)));
			helper.setRatioYoyAndMom(resultMap, kpiLimitValue, "KPI0069", KpiValueConst.KPI0070);
		} else {
			resultMap = conventOutOthersFeeList(list, resultMap, month, visitType, kpiLimitValue);
		}
		return resultMap;
	}

	private Map<String, Object> conventOutOthersFeeList(List<KpiSociationDTO> list, Map<String, Object> resultMap,
			String month, String visitType, Map<String, Object> kpiLimitValue) {
		for (KpiSociationDTO ksd : list) {
			if (KpiValueConst.KPI0070.equals(ksd.getKpiCode())) {
				resultMap.put("k0_3_2_2_fee_end",
						twoDecimals(helper.yuanToTenThousands(helper.filterNullValue(ksd.getKpiValue()))));
				resultMap.put(
						"k0_3_2_2_health_flag_end",
						helper.checkRation(helper.filterNullValue(ksd.getPeriodRatio()),
								helper.filterNullValue(ksd.getChainRatio()), setRatioMap("KPI0070", kpiLimitValue)));
				resultMap.put("k0_3_2_2_fee_cookie_end", helper.filterNullValue(ksd.getKpiValue()));
				resultMap.put("k0_3_2_2_yoy_end", twoDecimals(helper.filterNullValue(ksd.getPeriodRatio())).abs());
				resultMap.put("k0_3_2_2_yoy_flag_end",
						getAllRatioCompareResult(helper.filterNullValue(ksd.getPeriodRatio())));
				resultMap.put("k0_3_2_2_yoy_result_end", helper.checkFlag(helper.checkOneRation(
						helper.filterNullValue(ksd.getPeriodRatio()), setRatioMap("KPI0070", kpiLimitValue), 1)));
				resultMap.put("k0_3_2_2_mom_end", twoDecimals(helper.filterNullValue(ksd.getChainRatio())).abs());
				resultMap.put("k0_3_2_2_mom_flag_end",
						getAllRatioCompareResult(helper.filterNullValue(ksd.getChainRatio())));
				resultMap.put("k0_3_2_2_mom_result_end", helper.checkFlag(helper.checkOneRation(
						helper.filterNullValue(ksd.getChainRatio()), setRatioMap("KPI0070", kpiLimitValue), 2)));
			}
		}
		return helper.setRatioYoyAndMom(resultMap, kpiLimitValue, "KPI0069", KpiValueConst.KPI0070);
	}

	private Map<String, Object> getOutCheckFeeToWord(Map<String, Object> paramsMap, Map<String, Object> resultMap) {
		paramsMap.put("visitType", KpiValueConst.VISIT_OUT);
		GeneralMethods.getInstance().addAllValueToMap(getOutCheckKpiInfo(paramsMap), resultMap);
		return resultMap;
	}

	private Map<String, Object> getOutCheckKpiInfo(Map<String, Object> paramsMap) {
		String endMonth = paramsMap.get("currentDate").toString();
		String visitType = paramsMap.get("visitType").toString();
		String regionCode = paramsMap.get("regionCode").toString();
		Map<String, Object> resultMap = new HashMap<String, Object>();
		KpiConditionDTO c = new KpiConditionDTO();
		c.setSociationCode(regionCode);
		List<String> vl = new ArrayList<String>();
		vl.add(KpiValueConst.VISIT_OUT);
		c.setVisitTypeList(vl);
		List<String> kl = new ArrayList<String>();
		c.setKpiCodeList(kl);
		c.setPeriod(KpiValueConst.MONTH);
		String startMonth = helper.getStartDate(endMonth, -Constant.MONTH_THIRTYFIVE);
		c.setKpiTimeStart(startMonth);
		c.setKpiTimeEnd(endMonth);
		kl.add(KpiValueConst.KPI0025);
		List<KpiSociationDTO> dataList = kpiCoreDataService.queryKpiBySoc(c);
		resultMap = conventOutCheckListToMap(KpiValueConst.KPI0025, dataList, startMonth, endMonth, visitType,
				resultMap);
		kl.clear();
		kl.add(KpiValueConst.KPI0029);
		List<KpiSociationDTO> dataList1 = kpiCoreDataService.queryKpiBySoc(c);
		resultMap = conventOutCheckListToMap(KpiValueConst.KPI0029, dataList1, startMonth, endMonth, visitType,
				resultMap);
		kl.clear();
		kl.add(KpiValueConst.KPI0030);
		List<KpiSociationDTO> dataList2 = kpiCoreDataService.queryKpiBySoc(c);
		resultMap = conventOutCheckListToMap(KpiValueConst.KPI0030, dataList2, startMonth, endMonth, visitType,
				resultMap);
		kl.clear();
		kl.add(KpiValueConst.KPI0032);
		List<KpiSociationDTO> dataList3 = kpiCoreDataService.queryKpiBySoc(c);
		resultMap = conventOutCheckListToMap(KpiValueConst.KPI0032, dataList3, startMonth, endMonth, visitType,
				resultMap);
		kl.clear();
		kl.add(KpiValueConst.KPI0035);
		List<KpiSociationDTO> dataList4 = kpiCoreDataService.queryKpiBySoc(c);
		resultMap = conventOutCheckListToMap(KpiValueConst.KPI0035, dataList4, startMonth, endMonth, visitType,
				resultMap);
		kl.clear();
		kl.add(KpiValueConst.KPI0069);
		List<KpiSociationDTO> dataList5 = kpiCoreDataService.queryKpiBySoc(c);
		resultMap = conventOutCheckListToMap(KpiValueConst.KPI0069, dataList5, startMonth, endMonth, visitType,
				resultMap);
		return resultMap;
	}

	@SuppressWarnings("unchecked")
	private Map<String, Object> conventOutCheckListToMap(String kpiCode, List<KpiSociationDTO> dataList,
			String startMonth, String endMonth, String visitType, Map<String, Object> resultMap) {
		Map<String, Object> dataMap = getCheckCalculateDataMap(kpiCode, dataList, visitType, startMonth, endMonth);
		// // 将查询数据封装到List
		List<BigDecimal> periodList = (List<BigDecimal>) dataMap.get("periodList_end");
		List<BigDecimal> chainList = (List<BigDecimal>) dataMap.get("chainList_end");
		// // 总额
		List<BigDecimal> totalList = (List<BigDecimal>) dataMap.get("totalList_end");

		Map<String, Object> avgDataMap = getAvgData(periodList, chainList, totalList);

		// // 同期平均值计算
		List<BigDecimal> avgList = (List<BigDecimal>) avgDataMap.get("avgList");
		List<BigDecimal> RecentOneYear = helper.createSetListValue(Constant.MONTH_TWELVE, new BigDecimal(0));
		List<BigDecimal> periodLine = helper.createSetListValue(Constant.MONTH_TWELVE, new BigDecimal(0));
		List<BigDecimal> chainLine = helper.createSetListValue(Constant.MONTH_TWELVE, new BigDecimal(0));
		for (int i = 0; i < Constant.MONTH_TWELVE; i++) {
			RecentOneYear.set(i, helper.filterNullValue(totalList.get(totalList.size() + i - Constant.MONTH_TWELVE)));
			periodLine.set(i, helper.filterNullValue(periodList.get(periodList.size() + i - Constant.MONTH_TWELVE)));
			chainLine.set(i, helper.filterNullValue(chainList.get(chainList.size() + i - Constant.MONTH_TWELVE)));
		}
		if (KpiValueConst.KPI0025.equals(kpiCode)) {
			resultMap.put("k0_3_2_25_fee_gqynList_end", helper.toFixedUniqueOrgList(RecentOneYear));
			resultMap.put("k0_3_2_25_fee_gqsnList_end", helper.toFixedUniqueOrgList(avgList));
			resultMap.put("k0_3_2_25_fee_yoyList_end", helper.toFixedPercentList(periodLine));
			resultMap.put("k0_3_2_25_fee_momList_end", helper.toFixedPercentList(chainLine));
		}
		if (KpiValueConst.KPI0029.equals(kpiCode)) {
			resultMap.put("k0_3_2_2_fee_gqynList_end", helper.toFixedUniqueOrgList(RecentOneYear));
			resultMap.put("k0_3_2_2_fee_gqsnList_end", helper.toFixedUniqueOrgList(avgList));
			resultMap.put("k0_3_2_2_fee_yoyList_end", helper.toFixedPercentList(periodLine));
			resultMap.put("k0_3_2_2_fee_momList_end", helper.toFixedPercentList(chainLine));
		}
		if (KpiValueConst.KPI0030.equals(kpiCode)) {
			resultMap.put("k0_3_2_30_fee_gqynList_end", helper.toFixedUniqueOrgList(RecentOneYear));
			resultMap.put("k0_3_2_30_fee_gqsnList_end", helper.toFixedUniqueOrgList(avgList));
			resultMap.put("k0_3_2_30_fee_yoyList_end", helper.toFixedPercentList(periodLine));
			resultMap.put("k0_3_2_30_fee_momList_end", helper.toFixedPercentList(chainLine));
		}
		if (KpiValueConst.KPI0032.equals(kpiCode)) {
			resultMap.put("k0_3_2_32_fee_gqynList_end", helper.toFixedUniqueOrgList(RecentOneYear));
			resultMap.put("k0_3_2_32_fee_gqsnList_end", helper.toFixedUniqueOrgList(avgList));
			resultMap.put("k0_3_2_32_fee_yoyList_end", helper.toFixedPercentList(periodLine));
			resultMap.put("k0_3_2_32_fee_momList_end", helper.toFixedPercentList(chainLine));
		}
		if (KpiValueConst.KPI0035.equals(kpiCode)) {
			resultMap.put("k0_3_2_35_fee_gqynList_end", helper.toFixedUniqueOrgList(RecentOneYear));
			resultMap.put("k0_3_2_35_fee_gqsnList_end", helper.toFixedUniqueOrgList(avgList));
			resultMap.put("k0_3_2_35_fee_yoyList_end", helper.toFixedPercentList(periodLine));
			resultMap.put("k0_3_2_35_fee_momList_end", helper.toFixedPercentList(chainLine));
		}
		if (KpiValueConst.KPI0069.equals(kpiCode)) {
			resultMap.put("k0_3_2_69_fee_gqynList_end", helper.toFixedUniqueOrgList(RecentOneYear));
			resultMap.put("k0_3_2_69_fee_gqsnList_end", helper.toFixedUniqueOrgList(avgList));
			resultMap.put("k0_3_2_69_fee_yoyList_end", helper.toFixedPercentList(periodLine));
			resultMap.put("k0_3_2_69_fee_momList_end", helper.toFixedPercentList(chainLine));
		}
		return resultMap;
	}

	@Override
	public Map<String, Object> getHosGradeFeeToWordByGrade(Map<String, Object> paramsMap) {
		paramsMap.put("visitType", KpiValueConst.VISIT_HOS);
		Map<String, Object> resultMap = new HashMap<String, Object>();
		resultMap = getHosEveryGradeInfoByGrade(paramsMap);
		return resultMap;
	}

	// '1'按等级查询(hos)
	private Map<String, Object> getHosEveryGradeInfoByGrade(Map<String, Object> paramsMap) {
		// 设置查询条件
		String visitType = paramsMap.get("visitType").toString();
		String month = paramsMap.get("currentDate").toString();
		String regionCode = paramsMap.get("regionCode").toString();
		List<String> kpiList = new ArrayList<String>();
		Map<String, KpiSociationDTO> map = new HashMap<String, KpiSociationDTO>();
		// kpiList.add(KpiValueConst.KPI0001);
		kpiList.add(KpiValueConst.KPI0053);
		kpiList.add(KpiValueConst.KPI0025);
		kpiList.add(KpiValueConst.KPI0029);
		kpiList.add(KpiValueConst.KPI0030);
		kpiList.add(KpiValueConst.KPI0032);
		kpiList.add(KpiValueConst.KPI0035);
		kpiList.add(KpiValueConst.KPI0069);
		KpiConditionDTO kpiConditionDTO = new KpiConditionDTO();
		kpiConditionDTO.setVisitType(visitType);
		kpiConditionDTO.setKpiTime(month);
		kpiConditionDTO.setKpiCodeList(kpiList);
		kpiConditionDTO.setPeriod(Constants.perion_13); // 按照月份
		kpiConditionDTO.setSociationCode(regionCode);
		List<String> levelList = new ArrayList<String>();
		levelList.add(Constants.type_4);
		levelList.add(Constants.type_3);
		levelList.add(Constants.type_2);
		kpiConditionDTO.setGradeList(levelList);
		List<KpiGradeDTO> kpiGradeList = kpiCoreDataService.queryKpiByGrade(kpiConditionDTO);
		// 今年当月
		kpiConditionDTO.setKpiTime(month);

		KpiConditionDTO kpi0053Con = getKpiConditionByKpiCode(paramsMap, KpiValueConst.KPI0053);
		KpiConditionDTO kpi0025Con = getKpiConditionByKpiCode(paramsMap, KpiValueConst.KPI0025);
		KpiConditionDTO kpi0029Con = getKpiConditionByKpiCode(paramsMap, KpiValueConst.KPI0029);
		KpiConditionDTO kpi0030Con = getKpiConditionByKpiCode(paramsMap, KpiValueConst.KPI0030);
		KpiConditionDTO kpi0032Con = getKpiConditionByKpiCode(paramsMap, KpiValueConst.KPI0032);
		KpiConditionDTO kpi0035Con = getKpiConditionByKpiCode(paramsMap, KpiValueConst.KPI0035);
		KpiConditionDTO kpi0069Con = getKpiConditionByKpiCode(paramsMap, KpiValueConst.KPI0069);

		KpiSociationDTO medicalTotalFee = (KpiSociationDTO) this.kpiCoreDataService.querySingleKpiBySoc(kpi0053Con);
		KpiSociationDTO operationTotalFee = (KpiSociationDTO) this.kpiCoreDataService.querySingleKpiBySoc(kpi0025Con);
		KpiSociationDTO checkTotalFee = (KpiSociationDTO) this.kpiCoreDataService.querySingleKpiBySoc(kpi0029Con);
		KpiSociationDTO treatTotalFee = (KpiSociationDTO) this.kpiCoreDataService.querySingleKpiBySoc(kpi0030Con);
		KpiSociationDTO assayTotalFee = (KpiSociationDTO) this.kpiCoreDataService.querySingleKpiBySoc(kpi0032Con);
		KpiSociationDTO othersTotalFee = (KpiSociationDTO) this.kpiCoreDataService.querySingleKpiBySoc(kpi0035Con);
		KpiSociationDTO theRestTotalFee = (KpiSociationDTO) this.kpiCoreDataService.querySingleKpiBySoc(kpi0069Con);
		map.put("medicalTotalFee", medicalTotalFee);
		map.put("operationTotalFee", operationTotalFee);
		map.put("checkTotalFee", checkTotalFee);
		map.put("treatTotalFee", treatTotalFee);
		map.put("assayTotalFee", assayTotalFee);
		map.put("othersTotalFee", othersTotalFee);
		map.put("theRestTotalFee", theRestTotalFee);
		Map<String, Object> resultMap = createHosEveryKpiMapByGrade(kpiGradeList, paramsMap, map);
		return resultMap;
	}

	private Map<String, Object> createHosEveryKpiMapByGrade(List<KpiGradeDTO> kpiGradeList,
			Map<String, Object> paramsMap, Map<String, KpiSociationDTO> map) {
		String[] lv1 = { "一级及以下医院", "0.00", "0.00", "0.00", "0.00", "0.00", "0.00", "0.00", "0.00", "0.00", "0.00",
				"0.00", "0.00", "0.00", "0.00", "0.00", "0.00", "0.00", "0.00", "0.00", "0.00", "0.00" };// 一级以下
		String[] lv2 = { "二级医院", "0.00", "0.00", "0.00", "0.00", "0.00", "0.00", "0.00", "0.00", "0.00", "0.00",
				"0.00", "0.00", "0.00", "0.00", "0.00", "0.00", "0.00", "0.00", "0.00", "0.00", "0.00" };// 二级以下
		String[] lv3 = { "三级医院", "0.00", "0.00", "0.00", "0.00", "0.00", "0.00", "0.00", "0.00", "0.00", "0.00",
				"0.00", "0.00", "0.00", "0.00", "0.00", "0.00", "0.00", "0.00", "0.00", "0.00", "0.00" };// 三级以下
		String[] lv4 = { "合计", "0.00", "", "", "0.00", "", "", "0.00", "", "", "0.00", "", "", "0.00", "", "", "0.00",
				"", "", "0.00", "", "" };// 合计
		BigDecimal[] hosTotal = new BigDecimal[3];
		BigDecimal MedicalPercent = new BigDecimal(0);
		for (KpiGradeDTO dto : kpiGradeList) {
			if (Constants.type_4.equals(dto.getGrade())) {
				hosTotal[0] = getTypeInfo(lv1, hosTotal[0], dto, MedicalPercent);
			} else if (Constants.type_3.equals(dto.getGrade())) {
				hosTotal[1] = getTypeInfo(lv2, hosTotal[1], dto, MedicalPercent);
			} else if (Constants.type_2.equals(dto.getGrade())) {
				hosTotal[2] = getTypeInfo(lv3, hosTotal[2], dto, MedicalPercent);
			}
			lv4[1] = helper.yuanToTenThousands(
					helper.filterNullValue(map.get("medicalTotalFee") == null ? BigDecimal.ZERO : map.get(
							"medicalTotalFee").getKpiValue())).toString();
			lv4[4] = helper.yuanToTenThousands(
					helper.filterNullValue(map.get("checkTotalFee") == null ? BigDecimal.ZERO : map
							.get("checkTotalFee").getKpiValue())).toString();
			lv4[7] = helper.yuanToTenThousands(
					helper.filterNullValue(map.get("treatTotalFee") == null ? BigDecimal.ZERO : map
							.get("treatTotalFee").getKpiValue())).toString();
			lv4[10] = helper.yuanToTenThousands(
					helper.filterNullValue(map.get("operationTotalFee") == null ? BigDecimal.ZERO : map.get(
							"operationTotalFee").getKpiValue())).toString();
			lv4[13] = helper.yuanToTenThousands(
					helper.filterNullValue(map.get("othersTotalFee") == null ? BigDecimal.ZERO : map.get(
							"othersTotalFee").getKpiValue())).toString();
			lv4[16] = helper.yuanToTenThousands(
					helper.filterNullValue(map.get("assayTotalFee") == null ? BigDecimal.ZERO : map
							.get("assayTotalFee").getKpiValue())).toString();
			lv4[19] = helper.yuanToTenThousands(
					helper.filterNullValue(map.get("theRestTotalFee") == null ? BigDecimal.ZERO : map.get(
							"theRestTotalFee").getKpiValue())).toString();

		}

		hosTotal[0] = hosTotal[0] == null ? BigDecimal.ZERO : hosTotal[0];
		hosTotal[1] = hosTotal[1] == null ? BigDecimal.ZERO : hosTotal[1];
		hosTotal[2] = hosTotal[2] == null ? BigDecimal.ZERO : hosTotal[2];
		List<Object> list = new ArrayList<Object>();
		list.add(lv3);
		list.add(lv2);
		list.add(lv1);
		list.add(lv4);
		Map<String, Object> resultMap = new HashMap<String, Object>();
		resultMap.put("k1_2_2_1_yp_tableList_end", list);
		return resultMap;
	}

	private BigDecimal getTypeInfo(String[] lv, BigDecimal hosTotal, KpiGradeDTO dto, BigDecimal MedicalPercent) {
		if (KpiValueConst.KPI0053.equals(dto.getKpiCode())) {
			BigDecimal medicalFee = helper.yuanToTenThousands(helper.filterNullValue(dto.getKpiValue()));
			lv[1] = medicalFee.toString();
			lv[2] = helper.filterNullValue(dto.getPeriodRatio()).setScale(2, BigDecimal.ROUND_HALF_UP).toString();
			lv[3] = helper.filterNullValue(dto.getChainRatio()).setScale(2, BigDecimal.ROUND_HALF_UP).toString();
		}
		if (KpiValueConst.KPI0029.equals(dto.getKpiCode())) {
			BigDecimal operationFee = helper.yuanToTenThousands(helper.filterNullValue(dto.getKpiValue()));
			lv[4] = operationFee.toString();
			lv[5] = helper.filterNullValue(dto.getPeriodRatio()).setScale(2, BigDecimal.ROUND_HALF_UP).toString();
			lv[6] = helper.filterNullValue(dto.getChainRatio()).setScale(2, BigDecimal.ROUND_HALF_UP).toString();
		}
		if (KpiValueConst.KPI0030.equals(dto.getKpiCode())) {
			BigDecimal checkFee = helper.yuanToTenThousands(helper.filterNullValue(dto.getKpiValue()));
			lv[7] = checkFee.toString();
			lv[8] = helper.filterNullValue(dto.getPeriodRatio()).setScale(2, BigDecimal.ROUND_HALF_UP).toString();
			lv[9] = helper.filterNullValue(dto.getChainRatio()).setScale(2, BigDecimal.ROUND_HALF_UP).toString();
		}
		if (KpiValueConst.KPI0025.equals(dto.getKpiCode())) {
			BigDecimal treatFee = helper.yuanToTenThousands(helper.filterNullValue(dto.getKpiValue()));
			lv[10] = treatFee.toString();
			lv[11] = helper.filterNullValue(dto.getPeriodRatio()).setScale(2, BigDecimal.ROUND_HALF_UP).toString();
			lv[12] = helper.filterNullValue(dto.getChainRatio()).setScale(2, BigDecimal.ROUND_HALF_UP).toString();
		}
		if (KpiValueConst.KPI0035.equals(dto.getKpiCode())) {
			BigDecimal testFee = helper.yuanToTenThousands(helper.filterNullValue(dto.getKpiValue()));
			lv[13] = testFee.toString();
			lv[14] = helper.filterNullValue(dto.getPeriodRatio()).setScale(2, BigDecimal.ROUND_HALF_UP).toString();
			lv[15] = helper.filterNullValue(dto.getChainRatio()).setScale(2, BigDecimal.ROUND_HALF_UP).toString();
		}
		if (KpiValueConst.KPI0032.equals(dto.getKpiCode())) {
			BigDecimal othersFee = helper.yuanToTenThousands(helper.filterNullValue(dto.getKpiValue()));
			lv[16] = othersFee.toString();
			lv[17] = helper.filterNullValue(dto.getPeriodRatio()).setScale(2, BigDecimal.ROUND_HALF_UP).toString();
			lv[18] = helper.filterNullValue(dto.getChainRatio()).setScale(2, BigDecimal.ROUND_HALF_UP).toString();
		}
		if (KpiValueConst.KPI0069.equals(dto.getKpiCode())) {
			BigDecimal theRestFee = helper.yuanToTenThousands(helper.filterNullValue(dto.getKpiValue()));
			lv[19] = theRestFee.toString();
			lv[20] = helper.filterNullValue(dto.getPeriodRatio()).setScale(2, BigDecimal.ROUND_HALF_UP).toString();
			lv[21] = helper.filterNullValue(dto.getChainRatio()).setScale(2, BigDecimal.ROUND_HALF_UP).toString();
		}
		return hosTotal;
	}

	@Override
	public Map<String, Object> getOutGradeFeeToWordByGrade(Map<String, Object> paramsMap) {
		paramsMap.put("visitType", KpiValueConst.VISIT_OUT);
		Map<String, Object> resultMap = new HashMap<String, Object>();
		resultMap = getOutEveryGradeInfoByGrade(paramsMap);
		return resultMap;
	}

	private BigDecimal divideNotNullOrZero(BigDecimal fenzi, BigDecimal fenmu) {
		if (null == fenzi || null == fenmu || fenmu.doubleValue() == 0) {
			return BigDecimal.ZERO;
		}

		return fenzi.divide(fenmu, 4, BigDecimal.ROUND_HALF_UP);
	}

	private Map<String, Object> getOutEveryGradeInfoByGrade(Map<String, Object> paramsMap) {
		// 设置查询条件
		String visitType = paramsMap.get("visitType").toString();
		String month = paramsMap.get("currentDate").toString();
		String regionCode = paramsMap.get("regionCode").toString();
		List<String> kpiList = new ArrayList<String>();
		Map<String, KpiSociationDTO> map = new HashMap<String, KpiSociationDTO>();
		kpiList.add(KpiValueConst.KPI0053);
		kpiList.add(KpiValueConst.KPI0025);
		kpiList.add(KpiValueConst.KPI0029);
		kpiList.add(KpiValueConst.KPI0030);
		kpiList.add(KpiValueConst.KPI0032);
		kpiList.add(KpiValueConst.KPI0035);
		kpiList.add(KpiValueConst.KPI0069);
		KpiConditionDTO kpiConditionDTO = new KpiConditionDTO();
		kpiConditionDTO.setVisitType(visitType);
		kpiConditionDTO.setKpiTime(month);
		kpiConditionDTO.setKpiCodeList(kpiList);
		kpiConditionDTO.setPeriod(Constants.perion_13); // 按照月份
		kpiConditionDTO.setSociationCode(regionCode);
		List<String> levelList = new ArrayList<String>();
		levelList.add(Constants.type_4);
		levelList.add(Constants.type_3);
		levelList.add(Constants.type_2);
		kpiConditionDTO.setGradeList(levelList);
		List<KpiGradeDTO> kpiGradeList = this.kpiCoreDataService.queryKpiByGrade(kpiConditionDTO);
		// 今年当月
		kpiConditionDTO.setKpiTime(month);

		KpiConditionDTO kpi0025Con = getKpiConditionByKpiCode(paramsMap, KpiValueConst.KPI0025);
		KpiConditionDTO kpi0029Con = getKpiConditionByKpiCode(paramsMap, KpiValueConst.KPI0029);
		KpiConditionDTO kpi0030Con = getKpiConditionByKpiCode(paramsMap, KpiValueConst.KPI0030);
		KpiConditionDTO kpi0032Con = getKpiConditionByKpiCode(paramsMap, KpiValueConst.KPI0032);
		KpiConditionDTO kpi0035Con = getKpiConditionByKpiCode(paramsMap, KpiValueConst.KPI0035);
		KpiConditionDTO kpi0069Con = getKpiConditionByKpiCode(paramsMap, KpiValueConst.KPI0069);
		KpiConditionDTO kpi0053Con = getKpiConditionByKpiCode(paramsMap, KpiValueConst.KPI0053);

		KpiSociationDTO operationTotalFee = (KpiSociationDTO) this.kpiCoreDataService.querySingleKpiBySoc(kpi0025Con);
		KpiSociationDTO checkTotalFee = (KpiSociationDTO) this.kpiCoreDataService.querySingleKpiBySoc(kpi0029Con);
		KpiSociationDTO treatTotalFee = (KpiSociationDTO) this.kpiCoreDataService.querySingleKpiBySoc(kpi0030Con);
		KpiSociationDTO assayTotalFee = (KpiSociationDTO) this.kpiCoreDataService.querySingleKpiBySoc(kpi0032Con);
		KpiSociationDTO othersTotalFee = (KpiSociationDTO) this.kpiCoreDataService.querySingleKpiBySoc(kpi0035Con);
		KpiSociationDTO theRestTotalFee = (KpiSociationDTO) this.kpiCoreDataService.querySingleKpiBySoc(kpi0069Con);
		KpiSociationDTO medicalTotalFee = (KpiSociationDTO) this.kpiCoreDataService.querySingleKpiBySoc(kpi0053Con);
		map.put("medicalTotalFee", medicalTotalFee);
		map.put("operationTotalFee", operationTotalFee);
		map.put("checkTotalFee", checkTotalFee);
		map.put("treatTotalFee", treatTotalFee);
		map.put("assayTotalFee", assayTotalFee);
		map.put("othersTotalFee", othersTotalFee);
		map.put("theRestTotalFee", theRestTotalFee);
		Map<String, Object> resultMap = createOutEveryKpiMapByGrade(kpiGradeList, paramsMap, map);
		return resultMap;
	}

	private Map<String, Object> createOutEveryKpiMapByGrade(List<KpiGradeDTO> kpiGradeList,
			Map<String, Object> paramsMap, Map<String, KpiSociationDTO> map) {
		String[] lv1 = { "一级及以下医院", "0.00", "0.00", "0.00", "0.00", "0.00", "0.00", "0.00", "0.00", "0.00", "0.00",
				"0.00", "0.00", "0.00", "0.00", "0.00", "0.00", "0.00", "0.00", "0.00", "0.00", "0.00" };// 一级以下
		String[] lv2 = { "二级医院", "0.00", "0.00", "0.00", "0.00", "0.00", "0.00", "0.00", "0.00", "0.00", "0.00",
				"0.00", "0.00", "0.00", "0.00", "0.00", "0.00", "0.00", "0.00", "0.00", "0.00", "0.00" };// 二级以下
		String[] lv3 = { "三级医院", "0.00", "0.00", "0.00", "0.00", "0.00", "0.00", "0.00", "0.00", "0.00", "0.00",
				"0.00", "0.00", "0.00", "0.00", "0.00", "0.00", "0.00", "0.00", "0.00", "0.00", "0.00" };// 三级以下
		String[] lv4 = { "合计", "0.00", "", "", "0.00", "", "", "0.00", "", "", "0.00", "", "", "0.00", "", "", "0.00",
				"", "", "0.00", "", "" };// 合计
		BigDecimal[] hosTotal = new BigDecimal[3];
		BigDecimal MedicalPercent = new BigDecimal(0);
		for (KpiGradeDTO dto : kpiGradeList) {
			if (Constants.type_4.equals(dto.getGrade())) {
				hosTotal[0] = getTypeInfo(lv1, hosTotal[0], dto, MedicalPercent);
			} else if (Constants.type_3.equals(dto.getGrade())) {
				hosTotal[1] = getTypeInfo(lv2, hosTotal[1], dto, MedicalPercent);
			} else if (Constants.type_2.equals(dto.getGrade())) {
				hosTotal[2] = getTypeInfo(lv3, hosTotal[2], dto, MedicalPercent);
			}
			lv4[1] = helper.yuanToTenThousands(
					helper.filterNullValue(map.get("medicalTotalFee") == null ? BigDecimal.ZERO : map.get(
							"medicalTotalFee").getKpiValue())).toString();
			lv4[4] = helper.yuanToTenThousands(
					helper.filterNullValue(map.get("checkTotalFee") == null ? BigDecimal.ZERO : map
							.get("checkTotalFee").getKpiValue())).toString();
			lv4[7] = helper.yuanToTenThousands(
					helper.filterNullValue(map.get("treatTotalFee") == null ? BigDecimal.ZERO : map
							.get("treatTotalFee").getKpiValue())).toString();
			lv4[10] = helper.yuanToTenThousands(
					helper.filterNullValue(map.get("operationTotalFee") == null ? BigDecimal.ZERO : map.get(
							"operationTotalFee").getKpiValue())).toString();
			lv4[13] = helper.yuanToTenThousands(
					helper.filterNullValue(map.get("othersTotalFee") == null ? BigDecimal.ZERO : map.get(
							"othersTotalFee").getKpiValue())).toString();
			lv4[16] = helper.yuanToTenThousands(
					helper.filterNullValue(map.get("assayTotalFee") == null ? BigDecimal.ZERO : map
							.get("assayTotalFee").getKpiValue())).toString();
			lv4[19] = helper.yuanToTenThousands(
					helper.filterNullValue(map.get("theRestTotalFee") == null ? BigDecimal.ZERO : map.get(
							"theRestTotalFee").getKpiValue())).toString();
		}
		hosTotal[0] = hosTotal[0] == null ? BigDecimal.ZERO : hosTotal[0];
		hosTotal[1] = hosTotal[1] == null ? BigDecimal.ZERO : hosTotal[1];
		hosTotal[2] = hosTotal[2] == null ? BigDecimal.ZERO : hosTotal[2];
		List<Object> list = new ArrayList<Object>();
		list.add(lv3);
		list.add(lv2);
		list.add(lv1);
		list.add(lv4);
		Map<String, Object> resultMap = new HashMap<String, Object>();
		resultMap.put("k1_3_2_1_yp_tableList_end", list);
		return resultMap;
	}

	@Override
	public Map<String, Object> getHosMedicalFeeToWordByOrg(Map<String, Object> paramsMap,
			Map<String, Object> kpiLimitValue) {

		paramsMap.put("visitType", KpiValueConst.VISIT_HOS);
		paramsMap.put("kpiValue", KpiValueConst.KPI0053);
		Map<String, Object> resultMap = new HashMap<String, Object>();
		GeneralMethods.getInstance().addAllValueToMap(getHosMedicalKpiInfoByOrg(paramsMap, kpiLimitValue), resultMap);
		return resultMap;
	}

	// 住院药品费(单一机构)'2'
	private Map<String, Object> getHosMedicalKpiInfoByOrg(Map<String, Object> paramsMap,
			Map<String, Object> kpiLimitValue) {
		Map<String, Object> resultMap = new HashMap<String, Object>();
		String month = paramsMap.get("currentDate").toString();
		String visitType = paramsMap.get("visitType").toString();
		String regionCode = paramsMap.get("regionCode").toString();
		String orgCode = paramsMap.get("medicalOrgCode").toString();
		KpiConditionDTO c = new KpiConditionDTO();
		c.setOrgCode(orgCode);
		c.setSociationCode(regionCode);
		List<String> vl = new ArrayList<String>();
		vl.add(KpiValueConst.VISIT_HOS);
		c.setVisitTypeList(vl);
		List<String> kl = new ArrayList<String>();
		kl.add(KpiValueConst.KPI0053);
		c.setKpiCodeList(kl);
		c.setPeriod(KpiValueConst.MONTH);
		c.setKpiTime(month);
		List<KpiMedicalOrgDTO> list = kpiCoreDataService.queryKpiByOrg(c);
		if (list.isEmpty()) {
			resultMap.put("k2_2_2_1_Fee_end", "0.00");
			resultMap.put("k2_2_2_1_Fee_health_flag_end",
					helper.checkRation(new BigDecimal(0), new BigDecimal(0), setRatioMap("KPI0053", kpiLimitValue)));
			resultMap.put("k2_2_2_1_yoy_flag_end", getAllRatioCompareResult(new BigDecimal(0)));
			resultMap.put("k2_2_2_1_yoy_end", "0.00");
			resultMap.put("k2_2_2_1_yoy_result_end", helper.checkFlag(helper.checkOneRation(new BigDecimal(0),
					setRatioMap("KPI0053", kpiLimitValue), 1)));
			resultMap.put("k2_2_2_1_mom_flag_end", getAllRatioCompareResult(new BigDecimal(0)));
			resultMap.put("k2_2_2_1_mom_end", "0.00");
			resultMap.put("k2_2_2_1_mom_result_end", helper.checkFlag(helper.checkOneRation(new BigDecimal(0),
					setRatioMap("KPI0053", kpiLimitValue), 2)));
			helper.setRatioYoyAndMom(resultMap, kpiLimitValue, "KPI0005", KpiValueConst.KPI0053);
		} else {
			resultMap = conventHosMedicalListToMapByOrg(list, month, visitType, kpiLimitValue);
		}
		return resultMap;
	}

	private Map<String, Object> conventHosMedicalListToMapByOrg(List<KpiMedicalOrgDTO> list, String month,
			String visitType, Map<String, Object> kpiLimitValue) {
		Map<String, Object> result = new HashMap<String, Object>();
		for (KpiMedicalOrgDTO ksd : list) {
			if (KpiValueConst.KPI0053.equals(ksd.getKpiCode())) {
				result.put("k2_2_2_1_yoy_end", twoDecimals(helper.filterNullValue(ksd.getPeriodRatio())).abs());
				result.put("k2_2_2_1_mom_end", twoDecimals(helper.filterNullValue(ksd.getChainRatio())).abs());
				result.put("k2_2_2_1_Fee_end",
						twoDecimals(helper.yuanToTenThousands((helper.filterNullValue(ksd.getKpiValue())))));
				result.put("k2_2_2_1_Fee_cookie_end", helper.filterNullValue(ksd.getKpiValue()));
			}
			result.put(
					"k2_2_2_1_Fee_health_flag_end",
					helper.checkRation(helper.filterNullValue(ksd.getPeriodRatio()),
							helper.filterNullValue(ksd.getChainRatio()), setRatioMap("KPI0053", kpiLimitValue)));
			result.put("k2_2_2_1_yoy_flag_end", getAllRatioCompareResult(helper.filterNullValue(ksd.getPeriodRatio())));
			result.put(
					"k2_2_2_1_yoy_result_end",
					helper.checkFlag(helper.checkOneRation(helper.filterNullValue(ksd.getPeriodRatio()),
							setRatioMap("KPI0053", kpiLimitValue), 1)));
			result.put("k2_2_2_1_mom_flag_end", getAllRatioCompareResult(helper.filterNullValue(ksd.getChainRatio())));
			result.put(
					"k2_2_2_1_mom_result_end",
					helper.checkFlag(helper.checkOneRation(helper.filterNullValue(ksd.getChainRatio()),
							setRatioMap("KPI0053", kpiLimitValue), 2)));
		}
		return helper.setRatioYoyAndMom(result, kpiLimitValue, "KPI0005", KpiValueConst.KPI0053);
	}

	@Override
	public Map<String, Object> getHosOthersFeeToWordByOrg(Map<String, Object> paramsMap,
			Map<String, Object> kpiLimitValue) {
		paramsMap.put("visitType", KpiValueConst.VISIT_HOS);
		paramsMap.put("kpiValue", KpiValueConst.KPI0053);
		paramsMap.put("kpiValue", KpiValueConst.KPI0070);
		Map<String, Object> resultMap = new HashMap<String, Object>();
		resultMap = getHosEachKpiInfoByOrg(paramsMap, resultMap);
		resultMap = getHosOthersMedDatesByOrg(paramsMap, kpiLimitValue, resultMap);
		resultMap = getHosCheckKpiInfoByOrg(paramsMap, resultMap);
		return resultMap;
	}

	private Map<String, Object> getHosOthersMedDatesByOrg(Map<String, Object> paramsMap,
			Map<String, Object> kpiLimitValue, Map<String, Object> resultMap) {
		String month = paramsMap.get("currentDate").toString();
		String visitType = paramsMap.get("visitType").toString();
		String regionCode = paramsMap.get("regionCode").toString();
		KpiConditionDTO c = new KpiConditionDTO();
		c.setSociationCode(regionCode);
		List<String> vl = new ArrayList<String>();
		vl.add(KpiValueConst.VISIT_HOS);
		c.setVisitTypeList(vl);
		c.setOrgCode(paramsMap.get("medicalOrgCode").toString());
		List<String> kl = new ArrayList<String>();
		kl.add(KpiValueConst.KPI0070);
		c.setKpiCodeList(kl);
		c.setPeriod(KpiValueConst.MONTH);
		c.setKpiTime(month);
		List<KpiMedicalOrgDTO> list = kpiCoreDataService.queryKpiByOrg(c);
		if (list.isEmpty()) {
			resultMap.put("k2_2_2_2_fee_end", "0.00");
			resultMap.put(
					"k2_2_2_2_fee_health_flag_end",
					helper.checkFlag(helper.checkRation(new BigDecimal(0), new BigDecimal(0),
							setRatioMap("KPI0070", kpiLimitValue))));
			resultMap.put("k2_2_2_2_yoy_flag_end", getAllRatioCompareResult(new BigDecimal(0)));
			resultMap.put("k2_2_2_2_yoy_end", "0.00");
			resultMap.put("k2_2_2_2_yoy_result_end", helper.checkFlag(helper.checkOneRation(new BigDecimal(0),
					setRatioMap("KPI0070", kpiLimitValue), 1)));
			resultMap.put("k2_2_2_2_mom_flag_end", getAllRatioCompareResult(new BigDecimal(0)));
			resultMap.put("k2_2_2_2_mom_end", "0.00");
			resultMap.put("k2_2_2_2_mom_result_end", helper.checkFlag(helper.checkOneRation(new BigDecimal(0),
					setRatioMap("KPI0070", kpiLimitValue), 2)));
			helper.setRatioYoyAndMom(resultMap, kpiLimitValue, "KPI0069", KpiValueConst.KPI0070);
		} else {
			resultMap = conventHosOthersFeeListByOrg(resultMap, list, month, visitType, kpiLimitValue);
		}
		return resultMap;
	}

	private Map<String, Object> conventHosOthersFeeListByOrg(Map<String, Object> resultMap,
			List<KpiMedicalOrgDTO> list, String month, String visitType, Map<String, Object> kpiLimitValue) {
		for (KpiMedicalOrgDTO ksd : list) {
			if (KpiValueConst.KPI0070.equals(ksd.getKpiCode())) {
				resultMap.put("k2_2_2_2_fee_end",
						twoDecimals(helper.yuanToTenThousands(helper.filterNullValue(ksd.getKpiValue()))));
				resultMap.put(
						"k2_2_2_2_fee_health_flag_end",
						helper.checkRation(helper.filterNullValue(ksd.getPeriodRatio()),
								helper.filterNullValue(ksd.getChainRatio()), setRatioMap("KPI0070", kpiLimitValue)));
				resultMap.put("k2_2_2_2_fee_cookie_end", helper.filterNullValue(ksd.getKpiValue()));
				resultMap.put("k2_2_2_2_yoy_end", twoDecimals(helper.filterNullValue(ksd.getPeriodRatio())).abs());
				resultMap.put("k2_2_2_2_yoy_flag_end",
						getAllRatioCompareResult(helper.filterNullValue(ksd.getPeriodRatio())));
				resultMap.put("k2_2_2_2_yoy_result_end", helper.checkFlag(helper.checkOneRation(
						helper.filterNullValue(ksd.getPeriodRatio()), setRatioMap("KPI0070", kpiLimitValue), 1)));
				resultMap.put("k2_2_2_2_mom_end", twoDecimals(helper.filterNullValue(ksd.getChainRatio())).abs());
				resultMap.put("k2_2_2_2_mom_flag_end",
						getAllRatioCompareResult(helper.filterNullValue(ksd.getChainRatio())));
				resultMap.put("k2_2_2_2_mom_result_end", helper.checkFlag(helper.checkOneRation(
						helper.filterNullValue(ksd.getChainRatio()), setRatioMap("KPI0070", kpiLimitValue), 2)));
			}
		}
		return helper.setRatioYoyAndMom(resultMap, kpiLimitValue, "KPI0069", KpiValueConst.KPI0070);
	}

	// GHG 各项指标List '2'
	private Map<String, Object> getHosEachKpiInfoByOrg(Map<String, Object> paramsMap, Map<String, Object> resultMap) {
		String month = paramsMap.get("currentDate").toString();
		String visitType = paramsMap.get("visitType").toString();
		String regionCode = paramsMap.get("regionCode").toString();
		String orgCode = paramsMap.get("medicalOrgCode").toString();
		KpiConditionDTO c = new KpiConditionDTO();
		c.setSociationCode(regionCode);
		c.setOrgCode(orgCode);
		List<String> vl = new ArrayList<String>();
		vl.add(KpiValueConst.VISIT_HOS);
		c.setVisitTypeList(vl);
		List<String> kl = new ArrayList<String>();
		kl.add(KpiValueConst.KPI0025);
		kl.add(KpiValueConst.KPI0029);
		kl.add(KpiValueConst.KPI0030);
		kl.add(KpiValueConst.KPI0032);
		kl.add(KpiValueConst.KPI0035);
		kl.add(KpiValueConst.KPI0069);
		c.setKpiCodeList(kl);
		c.setPeriod(KpiValueConst.MONTH);
		c.setKpiTime(month);
		List<KpiMedicalOrgDTO> list = kpiCoreDataService.queryKpiByOrg(c);
		if (list.isEmpty()) {
			String[] l1 = { "检 查 费", "0.00", "0.00", "0.00", "0.00" };// 检查费
			String[] l2 = { "治 疗 费", "0.00", "0.00", "0.00", "0.00" };// 治疗费
			String[] l3 = { "手 术 费", "0.00", "0.00", "0.00", "0.00" };// 手术费
			String[] l4 = { "化 验 费", "0.00", "0.00", "0.00", "0.00" };// 化验费
			String[] l5 = { "其 他 费", "0.00", "0.00", "0.00", "0.00" };// 其他费
			String[] l6 = { "其 余 费 用", "0.00", "0.00", "0.00", "0.00" };// 其余费用
			String[] l7 = { "合 计", "0.00", "0.00", "", "" };// 合计
			List<Object> kpiList = new ArrayList<Object>();
			kpiList.add(l1);
			kpiList.add(l2);
			kpiList.add(l3);
			kpiList.add(l4);
			kpiList.add(l5);
			kpiList.add(l6);
			kpiList.add(l7);
			resultMap.put("k2_2_2_2_fee_tableList_end", kpiList);
		} else {
			resultMap = conventHosEveryKpiListToMapByOrg(list, month, visitType);
		}
		return resultMap;
	}

	private Map<String, Object> conventHosEveryKpiListToMapByOrg(List<KpiMedicalOrgDTO> list, String month,
			String visitType) {
		String[] l1 = { "检 查 费", "0.00", "0.00", "0.00", "0.00" };// 检查费
		String[] l2 = { "治 疗 费", "0.00", "0.00", "0.00", "0.00" };// 治疗费
		String[] l3 = { "手 术 费", "0.00", "0.00", "0.00", "0.00" };// 手术费
		String[] l4 = { "化 验 费", "0.00", "0.00", "0.00", "0.00" };// 化验费
		String[] l5 = { "其 他 费", "0.00", "0.00", "0.00", "0.00" };// 其他费
		String[] l6 = { "其 余 费 用", "0.00", "0.00", "0.00", "0.00" };// 其余费用
		String[] l7 = { "合 计", "0.00", "0.00", "", "" };// 合计
		List<Object> kpiList = new ArrayList<Object>();
		List<Object> kpiFeeList = new ArrayList<Object>();
		String[] exactCheckFee = { "检 查 费", "0.00" };
		String[] exactTreatFee = { "治 疗 费", "0.00" };
		String[] exactOperationFee = { "手 术 费", "0.00" };
		String[] exactAssayFee = { "化 验 费", "0.00" };
		String[] exactOthersFee = { "其 他 费", "0.00" };
		String[] exactTheRestFee = { "其 余 费 用", "0.00" };
		Map<String, Object> resultMap = new HashMap<String, Object>();
		Map<String, BigDecimal> fee = new HashMap<String, BigDecimal>();
		for (KpiMedicalOrgDTO kst : list) {
			if (KpiValueConst.KPI0029.equals(kst.getKpiCode())) {
				l1[1] = helper.yuanToTenThousands(kst.getKpiValue()).toString();
				BigDecimal checkFee = kst.getKpiValue();
				fee.put("checkFee", checkFee);
				exactCheckFee[1] = checkFee.toString();
				fee.put("kpi0029Value", new BigDecimal(l1[1]));
				l1[3] = helper.filterNullValue(kst.getPeriodRatio()).setScale(2, BigDecimal.ROUND_HALF_UP).toString();
				l1[4] = helper.filterNullValue(kst.getChainRatio()).setScale(2, BigDecimal.ROUND_HALF_UP).toString();
			}
			if (KpiValueConst.KPI0030.equals(kst.getKpiCode())) {
				l2[1] = helper.yuanToTenThousands(kst.getKpiValue()).toString();
				BigDecimal treatFee = kst.getKpiValue();
				fee.put("treatFee", treatFee);
				exactTreatFee[1] = treatFee.toString();
				fee.put("kpi0030Value", new BigDecimal(l2[1]));
				l2[3] = helper.filterNullValue(kst.getPeriodRatio()).setScale(2, BigDecimal.ROUND_HALF_UP).toString();
				l2[4] = helper.filterNullValue(kst.getChainRatio()).setScale(2, BigDecimal.ROUND_HALF_UP).toString();
			}
			if (KpiValueConst.KPI0025.equals(kst.getKpiCode())) {
				l3[1] = helper.yuanToTenThousands(kst.getKpiValue()).toString();
				BigDecimal operationFee = kst.getKpiValue();
				fee.put("operationFee", operationFee);
				exactOperationFee[1] = operationFee.toString();
				fee.put("kpi0025Value", new BigDecimal(l3[1]));
				l3[3] = helper.filterNullValue(kst.getPeriodRatio()).setScale(2, BigDecimal.ROUND_HALF_UP).toString();
				l3[4] = helper.filterNullValue(kst.getChainRatio()).setScale(2, BigDecimal.ROUND_HALF_UP).toString();
			}
			if (KpiValueConst.KPI0032.equals(kst.getKpiCode())) {
				l4[1] = helper.yuanToTenThousands(kst.getKpiValue()).toString();
				BigDecimal assayFee = kst.getKpiValue();
				fee.put("assayFee", assayFee);
				exactAssayFee[1] = assayFee.toString();
				fee.put("kpi0032Value", new BigDecimal(l4[1]));
				l4[3] = helper.filterNullValue(kst.getPeriodRatio()).setScale(2, BigDecimal.ROUND_HALF_UP).toString();
				l4[4] = helper.filterNullValue(kst.getChainRatio()).setScale(2, BigDecimal.ROUND_HALF_UP).toString();
			}
			if (KpiValueConst.KPI0035.equals(kst.getKpiCode())) {
				l5[1] = helper.yuanToTenThousands(kst.getKpiValue()).toString();
				BigDecimal othersFee = kst.getKpiValue();
				fee.put("othersFee", othersFee);
				exactOthersFee[1] = othersFee.toString();
				fee.put("kpi0035Value", new BigDecimal(l5[1]));
				l5[3] = helper.filterNullValue(kst.getPeriodRatio()).setScale(2, BigDecimal.ROUND_HALF_UP).toString();
				l5[4] = helper.filterNullValue(kst.getChainRatio()).setScale(2, BigDecimal.ROUND_HALF_UP).toString();
			}
			if (KpiValueConst.KPI0069.equals(kst.getKpiCode())) {
				l6[1] = helper.yuanToTenThousands(kst.getKpiValue()).toString();
				BigDecimal theRestFee = kst.getKpiValue();
				fee.put("theRestFee", theRestFee);
				exactTheRestFee[1] = theRestFee.toString();
				fee.put("kpi0069Value", new BigDecimal(l6[1]));
				l6[3] = helper.filterNullValue(kst.getPeriodRatio()).setScale(2, BigDecimal.ROUND_HALF_UP).toString();
				l6[4] = helper.filterNullValue(kst.getChainRatio()).setScale(2, BigDecimal.ROUND_HALF_UP).toString();
			}
		}
		kpiFeeList.add(exactCheckFee);
		kpiFeeList.add(exactTreatFee);
		kpiFeeList.add(exactOperationFee);
		kpiFeeList.add(exactAssayFee);
		kpiFeeList.add(exactOthersFee);
		kpiFeeList.add(exactTheRestFee);
		resultMap.put("k2_2_2_2_fee_pieList_end", kpiFeeList);
		BigDecimal exactTotalFee = helper.filterNullValue(fee.get("checkFee"))
				.add(helper.filterNullValue(fee.get("treatFee"))).add(helper.filterNullValue(fee.get("operationFee")))
				.add(helper.filterNullValue(fee.get("assayFee"))).add(helper.filterNullValue(fee.get("othersFee")))
				.add(helper.filterNullValue(fee.get("theRestFee")));
		BigDecimal total = helper.filterNullValue(fee.get("kpi0029Value"))
				.add(helper.filterNullValue(fee.get("kpi0025Value")))
				.add(helper.filterNullValue(fee.get("kpi0030Value")))
				.add(helper.filterNullValue(fee.get("kpi0032Value")))
				.add(helper.filterNullValue(fee.get("kpi0035Value")))
				.add(helper.filterNullValue(fee.get("kpi0069Value"))).setScale(2, BigDecimal.ROUND_HALF_UP);
		l7[1] = total.toString();
		BigDecimal checkPercent = divideNotNullOrZero(fee.get("checkFee"), exactTotalFee).multiply(new BigDecimal(100))
				.setScale(2, BigDecimal.ROUND_HALF_UP);
		l1[2] = checkPercent.toString();
		BigDecimal treatPercent = divideNotNullOrZero(fee.get("treatFee"), exactTotalFee).multiply(new BigDecimal(100))
				.setScale(2, BigDecimal.ROUND_HALF_UP);
		l2[2] = treatPercent.toString();
		BigDecimal operationPercent = divideNotNullOrZero(fee.get("operationFee"), exactTotalFee).multiply(
				new BigDecimal(100)).setScale(2, BigDecimal.ROUND_HALF_UP);
		l3[2] = operationPercent.toString();
		BigDecimal assayPercent = divideNotNullOrZero(fee.get("assayFee"), exactTotalFee).multiply(new BigDecimal(100))
				.setScale(2, BigDecimal.ROUND_HALF_UP);
		l4[2] = assayPercent.toString();
		BigDecimal exactPercent = divideNotNullOrZero(fee.get("othersFee"), exactTotalFee)
				.multiply(new BigDecimal(100)).setScale(2, BigDecimal.ROUND_HALF_UP);
		l5[2] = exactPercent.toString();
		BigDecimal theRestPercent = divideNotNullOrZero(fee.get("theRestFee"), exactTotalFee).multiply(
				new BigDecimal(100)).setScale(2, BigDecimal.ROUND_HALF_UP);
		l6[2] = theRestPercent.toString();
		l7[2] = "100.00";
		kpiList.add(l1);
		kpiList.add(l2);
		kpiList.add(l3);
		kpiList.add(l4);
		kpiList.add(l5);
		kpiList.add(l6);
		kpiList.add(l7);
		resultMap.put("k2_2_2_2_fee_tableList_end", kpiList);
		return resultMap;
	}

	// 单一机构 住院 检查费
	private Map<String, Object> getHosCheckKpiInfoByOrg(Map<String, Object> paramsMap, Map<String, Object> resultMap) {
		paramsMap.put("visitType", KpiValueConst.VISIT_HOS);
		// paramsMap.put("kpiValue", KpiValueConst.KPI0029);
		GeneralMethods.getInstance().addAllValueToMap(getHosCheckKpiByOrg(paramsMap), resultMap);
		return resultMap;
	}

	private Map<String, Object> getHosCheckKpiByOrg(Map<String, Object> paramsMap) {
		String endMonth = paramsMap.get("currentDate").toString();
		String visitType = paramsMap.get("visitType").toString();
		String regionCode = paramsMap.get("regionCode").toString();
		Map<String, Object> resultMap = new HashMap<String, Object>();
		KpiConditionDTO c = new KpiConditionDTO();
		c.setSociationCode(regionCode);
		List<String> vl = new ArrayList<String>();
		vl.add(KpiValueConst.VISIT_HOS);
		c.setOrgCode(paramsMap.get("medicalOrgCode").toString());
		c.setVisitTypeList(vl);
		List<String> kl = new ArrayList<String>();
		c.setKpiCodeList(kl);
		c.setPeriod(KpiValueConst.MONTH);
		String startMonth = helper.getStartDate(endMonth, -Constant.MONTH_THIRTYFIVE);
		c.setKpiTimeStart(startMonth);
		c.setKpiTimeEnd(endMonth);
		kl.add(KpiValueConst.KPI0025);
		List<KpiMedicalOrgDTO> dataList = kpiCoreDataService.queryKpiByOrg(c);
		resultMap = conventHosCheckOrgListToMap(KpiValueConst.KPI0025, dataList, startMonth, endMonth, visitType,
				resultMap);
		kl.clear();
		kl.add(KpiValueConst.KPI0029);
		List<KpiMedicalOrgDTO> dataList1 = kpiCoreDataService.queryKpiByOrg(c);
		resultMap = conventHosCheckOrgListToMap(KpiValueConst.KPI0029, dataList1, startMonth, endMonth, visitType,
				resultMap);
		kl.clear();
		kl.add(KpiValueConst.KPI0030);
		List<KpiMedicalOrgDTO> dataList2 = kpiCoreDataService.queryKpiByOrg(c);
		resultMap = conventHosCheckOrgListToMap(KpiValueConst.KPI0030, dataList2, startMonth, endMonth, visitType,
				resultMap);
		kl.clear();
		kl.add(KpiValueConst.KPI0032);
		List<KpiMedicalOrgDTO> dataList3 = kpiCoreDataService.queryKpiByOrg(c);
		resultMap = conventHosCheckOrgListToMap(KpiValueConst.KPI0032, dataList3, startMonth, endMonth, visitType,
				resultMap);
		kl.clear();
		kl.add(KpiValueConst.KPI0035);
		List<KpiMedicalOrgDTO> dataList4 = kpiCoreDataService.queryKpiByOrg(c);
		resultMap = conventHosCheckOrgListToMap(KpiValueConst.KPI0035, dataList4, startMonth, endMonth, visitType,
				resultMap);
		kl.clear();
		kl.add(KpiValueConst.KPI0069);
		List<KpiMedicalOrgDTO> dataList5 = kpiCoreDataService.queryKpiByOrg(c);
		resultMap = conventHosCheckOrgListToMap(KpiValueConst.KPI0069, dataList5, startMonth, endMonth, visitType,
				resultMap);
		return resultMap;
	}

	@SuppressWarnings("unchecked")
	private Map<String, Object> conventHosCheckOrgListToMap(String kpiCode, List<KpiMedicalOrgDTO> dataList,
			String startMonth, String endMonth, String visitType, Map<String, Object> resultMap) {
		Map<String, Object> dataMap = getCheckCalculateOrgDataMap(kpiCode, dataList, visitType, startMonth, endMonth);
		// // 将查询数据封装到List
		List<BigDecimal> periodList = (List<BigDecimal>) dataMap.get("periodList_end");
		List<BigDecimal> chainList = (List<BigDecimal>) dataMap.get("chainList_end");
		// // 总额
		List<BigDecimal> totalList = (List<BigDecimal>) dataMap.get("totalList_end");

		Map<String, Object> avgDataMap = getAvgData(periodList, chainList, totalList);

		// // 同期平均值计算
		List<BigDecimal> avgList = (List<BigDecimal>) avgDataMap.get("avgList");
		List<BigDecimal> RecentOneYear = helper.createSetListValue(Constant.MONTH_TWELVE, new BigDecimal(0));
		List<BigDecimal> periodLine = helper.createSetListValue(Constant.MONTH_TWELVE, new BigDecimal(0));
		List<BigDecimal> chainLine = helper.createSetListValue(Constant.MONTH_TWELVE, new BigDecimal(0));
		for (int i = 0; i < Constant.MONTH_TWELVE; i++) {
			RecentOneYear.set(i, helper.filterNullValue(totalList.get(totalList.size() + i - Constant.MONTH_TWELVE)));
			periodLine.set(i, helper.filterNullValue(periodList.get(periodList.size() + i - Constant.MONTH_TWELVE)));
			chainLine.set(i, helper.filterNullValue(chainList.get(chainList.size() + i - Constant.MONTH_TWELVE)));
		}
		if (KpiValueConst.KPI0025.equals(kpiCode)) {
			resultMap.put("k2_2_2_25_fee_gqynList_end", helper.toFixedUniqueOrgList(RecentOneYear));
			resultMap.put("k2_2_2_25_fee_gqsnList_end", helper.toFixedUniqueOrgList(avgList));
			resultMap.put("k2_2_2_25_fee_yoyList_end", helper.toFixedPercentList(periodLine));
			resultMap.put("k2_2_2_25_fee_momList_end", helper.toFixedPercentList(chainLine));
		}
		if (KpiValueConst.KPI0029.equals(kpiCode)) {
			resultMap.put("k2_2_2_2_fee_gqynList_end", helper.toFixedUniqueOrgList(RecentOneYear));
			resultMap.put("k2_2_2_2_fee_gqsnList_end", helper.toFixedUniqueOrgList(avgList));
			resultMap.put("k2_2_2_2_fee_yoyList_end", helper.toFixedPercentList(periodLine));
			resultMap.put("k2_2_2_2_fee_momList_end", helper.toFixedPercentList(chainLine));
		}
		if (KpiValueConst.KPI0030.equals(kpiCode)) {
			resultMap.put("k2_2_2_30_fee_gqynList_end", helper.toFixedUniqueOrgList(RecentOneYear));
			resultMap.put("k2_2_2_30_fee_gqsnList_end", helper.toFixedUniqueOrgList(avgList));
			resultMap.put("k2_2_2_30_fee_yoyList_end", helper.toFixedPercentList(periodLine));
			resultMap.put("k2_2_2_30_fee_momList_end", helper.toFixedPercentList(chainLine));
		}
		if (KpiValueConst.KPI0032.equals(kpiCode)) {
			resultMap.put("k2_2_2_32_fee_gqynList_end", helper.toFixedUniqueOrgList(RecentOneYear));
			resultMap.put("k2_2_2_32_fee_gqsnList_end", helper.toFixedUniqueOrgList(avgList));
			resultMap.put("k2_2_2_32_fee_yoyList_end", helper.toFixedPercentList(periodLine));
			resultMap.put("k2_2_2_32_fee_momList_end", helper.toFixedPercentList(chainLine));
		}
		if (KpiValueConst.KPI0035.equals(kpiCode)) {
			resultMap.put("k2_2_2_35_fee_gqynList_end", helper.toFixedUniqueOrgList(RecentOneYear));
			resultMap.put("k2_2_2_35_fee_gqsnList_end", helper.toFixedUniqueOrgList(avgList));
			resultMap.put("k2_2_2_35_fee_yoyList_end", helper.toFixedPercentList(periodLine));
			resultMap.put("k2_2_2_35_fee_momList_end", helper.toFixedPercentList(chainLine));
		}
		if (KpiValueConst.KPI0069.equals(kpiCode)) {
			resultMap.put("k2_2_2_69_fee_gqynList_end", helper.toFixedUniqueOrgList(RecentOneYear));
			resultMap.put("k2_2_2_69_fee_gqsnList_end", helper.toFixedUniqueOrgList(avgList));
			resultMap.put("k2_2_2_69_fee_yoyList_end", helper.toFixedPercentList(periodLine));
			resultMap.put("k2_2_2_69_fee_momList_end", helper.toFixedPercentList(chainLine));
		}
		return resultMap;
	}

	@Override
	public Map<String, Object> getOutMedicalFeeToWordByOrg(Map<String, Object> paramsMap,
			Map<String, Object> kpiLimitValue) {
		paramsMap.put("visitType", KpiValueConst.VISIT_OUT);
		paramsMap.put("kpiValue", KpiValueConst.KPI0053);
		Map<String, Object> resultMap = new HashMap<String, Object>();
		GeneralMethods.getInstance().addAllValueToMap(getOutMedicalKpiInfoByOrg(paramsMap, kpiLimitValue), resultMap);
		return resultMap;
	}

	// 门诊药品费(单一机构)'2'
	private Map<String, Object> getOutMedicalKpiInfoByOrg(Map<String, Object> paramsMap,
			Map<String, Object> kpiLimitValue) {
		Map<String, Object> resultMap = new HashMap<String, Object>();
		String month = paramsMap.get("currentDate").toString();
		String visitType = paramsMap.get("visitType").toString();
		String regionCode = paramsMap.get("regionCode").toString();
		String orgCode = paramsMap.get("medicalOrgCode").toString();
		KpiConditionDTO c = new KpiConditionDTO();
		c.setOrgCode(orgCode);
		c.setSociationCode(regionCode);
		List<String> vl = new ArrayList<String>();
		vl.add(KpiValueConst.VISIT_OUT);
		c.setVisitTypeList(vl);
		List<String> kl = new ArrayList<String>();
		kl.add(KpiValueConst.KPI0053);
		c.setKpiCodeList(kl);
		c.setPeriod(KpiValueConst.MONTH);
		c.setKpiTime(month);
		List<KpiMedicalOrgDTO> list = kpiCoreDataService.queryKpiByOrg(c);
		if (list.isEmpty()) {
			resultMap.put("k2_3_2_1_Fee_end", "0.00");
			resultMap.put("k2_3_2_1_Fee_health_flag_end",
					helper.checkRation(new BigDecimal(0), new BigDecimal(0), setRatioMap("KPI0053", kpiLimitValue)));
			resultMap.put("k2_3_2_1_yoy_flag_end", getAllRatioCompareResult(new BigDecimal(0)));
			resultMap.put("k2_3_2_1_yoy_end", "0.00");
			resultMap.put("k2_3_2_1_yoy_result_end", helper.checkFlag(helper.checkOneRation(new BigDecimal(0),
					setRatioMap("KPI0053", kpiLimitValue), 1)));
			resultMap.put("k2_3_2_1_mom_flag_end", getAllRatioCompareResult(new BigDecimal(0)));
			resultMap.put("k2_3_2_1_mom_end", "0.00");
			resultMap.put("k2_3_2_1_mom_result_end", helper.checkFlag(helper.checkOneRation(new BigDecimal(0),
					setRatioMap("KPI0053", kpiLimitValue), 2)));

			helper.setRatioYoyAndMom(resultMap, kpiLimitValue, "KPI0005", KpiValueConst.KPI0053);

		} else {
			resultMap = conventMedicalListToMapByOrg(list, month, visitType, kpiLimitValue);
		}
		return resultMap;
	}

	private Map<String, Object> conventMedicalListToMapByOrg(List<KpiMedicalOrgDTO> list, String month,
			String visitType, Map<String, Object> kpiLimitValue) {
		Map<String, Object> result = new HashMap<String, Object>();
		for (KpiMedicalOrgDTO ksd : list) {
			if (KpiValueConst.KPI0053.equals(ksd.getKpiCode())) {
				result.put("k2_3_2_1_Fee_cookie_end", helper.filterNullValue(ksd.getKpiValue()));
				result.put("k2_3_2_1_Fee_end",
						twoDecimals(helper.yuanToTenThousands((helper.filterNullValue(ksd.getKpiValue())))));
				result.put("k2_3_2_1_yoy_end", twoDecimals((helper.filterNullValue(ksd.getPeriodRatio()))).abs());
				result.put("k2_3_2_1_mom_end", twoDecimals((helper.filterNullValue(ksd.getChainRatio()))).abs());
			}
			result.put(
					"k2_3_2_1_Fee_health_flag_end",
					helper.checkRation(helper.filterNullValue(ksd.getPeriodRatio()),
							helper.filterNullValue(ksd.getChainRatio()), setRatioMap("KPI0053", kpiLimitValue)));
			result.put("k2_3_2_1_yoy_flag_end", getAllRatioCompareResult(helper.filterNullValue(ksd.getPeriodRatio())));
			result.put(
					"k2_3_2_1_yoy_result_end",
					helper.checkFlag(helper.checkOneRation(helper.filterNullValue(ksd.getPeriodRatio()),
							setRatioMap("KPI0053", kpiLimitValue), 1)));
			result.put("k2_3_2_1_mom_flag_end", getAllRatioCompareResult(helper.filterNullValue(ksd.getChainRatio())));
			result.put(
					"k2_3_2_1_mom_result_end",
					helper.checkFlag(helper.checkOneRation(helper.filterNullValue(ksd.getChainRatio()),
							setRatioMap("KPI0053", kpiLimitValue), 2)));
		}
		return helper.setRatioYoyAndMom(result, kpiLimitValue, "KPI0005", KpiValueConst.KPI0053);
	}

	@Override
	public Map<String, Object> getOutOthersFeeToWordByOrg(Map<String, Object> paramsMap,
			Map<String, Object> kpiLimitValue) {
		paramsMap.put("visitType", KpiValueConst.VISIT_OUT);
		Map<String, Object> resultMap = new HashMap<String, Object>();
		resultMap = getOutEachKpiInfoByOrg(paramsMap, resultMap);
		resultMap = getOutOthersMedDatesByOrg(paramsMap, kpiLimitValue, resultMap);
		resultMap = getOutCheckKpiInfoByOrg(paramsMap, resultMap);
		return resultMap;
	}

	// GHG 门诊各项指标List '2'
	private Map<String, Object> getOutEachKpiInfoByOrg(Map<String, Object> paramsMap, Map<String, Object> resultMap) {
		String month = paramsMap.get("currentDate").toString();
		String visitType = paramsMap.get("visitType").toString();
		String regionCode = paramsMap.get("regionCode").toString();
		String orgCode = paramsMap.get("medicalOrgCode").toString();
		KpiConditionDTO c = new KpiConditionDTO();
		c.setSociationCode(regionCode);
		c.setOrgCode(orgCode);
		List<String> vl = new ArrayList<String>();
		vl.add(KpiValueConst.VISIT_OUT);
		c.setVisitTypeList(vl);
		List<String> kl = new ArrayList<String>();
		kl.add(KpiValueConst.KPI0025);
		kl.add(KpiValueConst.KPI0029);
		kl.add(KpiValueConst.KPI0030);
		kl.add(KpiValueConst.KPI0032);
		kl.add(KpiValueConst.KPI0035);
		kl.add(KpiValueConst.KPI0069);
		c.setKpiCodeList(kl);
		c.setPeriod(KpiValueConst.MONTH);
		c.setKpiTime(month);
		List<KpiMedicalOrgDTO> list = kpiCoreDataService.queryKpiByOrg(c);
		if (list.isEmpty()) {
			String[] l1 = { "检 查 费", "0.00", "0.00", "0.00", "0.00" };// 检查费
			String[] l2 = { "治 疗 费", "0.00", "0.00", "0.00", "0.00" };// 治疗费
			String[] l3 = { "手 术 费", "0.00", "0.00", "0.00", "0.00" };// 手术费
			String[] l4 = { "化 验 费", "0.00", "0.00", "0.00", "0.00" };// 化验费
			String[] l5 = { "其 他 费", "0.00", "0.00", "0.00", "0.00" };// 其他费
			String[] l6 = { "其 余 费 用", "0.00", "0.00", "0.00", "0.00" };// 其余费用
			String[] l7 = { "合 计", "0.00", "0.00", "", "" };// 合计
			List<Object> kpiList = new ArrayList<Object>();
			kpiList.add(l1);
			kpiList.add(l2);
			kpiList.add(l3);
			kpiList.add(l4);
			kpiList.add(l5);
			kpiList.add(l6);
			kpiList.add(l7);
			resultMap.put("k2_3_2_2_fee_tableList_end", kpiList);
		} else {
			resultMap = conventOutEveryKpiListToMapByOrg(list, month, visitType);
		}
		return resultMap;
	}

	private Map<String, Object> conventOutEveryKpiListToMapByOrg(List<KpiMedicalOrgDTO> list, String month,
			String visitType) {
		String[] l1 = { "检 查 费", "0.00", "0.00", "0.00", "0.00" };// 检查费
		String[] l2 = { "治 疗 费", "0.00", "0.00", "0.00", "0.00" };// 治疗费
		String[] l3 = { "手 术 费", "0.00", "0.00", "0.00", "0.00" };// 手术费
		String[] l4 = { "化 验 费", "0.00", "0.00", "0.00", "0.00" };// 化验费
		String[] l5 = { "其 他 费", "0.00", "0.00", "0.00", "0.00" };// 其他费
		String[] l6 = { "其 余 费 用", "0.00", "0.00", "0.00", "0.00" };// 其余费用
		String[] l7 = { "合 计", "0.00", "0.00", "", "" };// 合计
		List<Object> kpiList = new ArrayList<Object>();
		List<Object> kpiFeeList = new ArrayList<Object>();
		String[] exactCheckFee = { "检 查 费", "0.00" };
		String[] exactTreatFee = { "治 疗 费", "0.00" };
		String[] exactOperationFee = { "手 术 费", "0.00" };
		String[] exactAssayFee = { "化 验 费", "0.00" };
		String[] exactOthersFee = { "其 他 费", "0.00" };
		String[] exactTheRestFee = { "其 余 费 用", "0.00" };
		Map<String, Object> resultMap = new HashMap<String, Object>();
		Map<String, BigDecimal> fee = new HashMap<String, BigDecimal>();
		for (KpiMedicalOrgDTO kst : list) {
			if (KpiValueConst.KPI0029.equals(kst.getKpiCode())) {
				l1[1] = helper.yuanToTenThousands(kst.getKpiValue()).toString();
				BigDecimal checkFee = kst.getKpiValue();
				fee.put("checkFee", checkFee);
				exactCheckFee[1] = checkFee.toString();
				fee.put("kpi0029Value", new BigDecimal(l1[1]));
				l1[3] = helper.filterNullValue(kst.getPeriodRatio()).setScale(2, BigDecimal.ROUND_HALF_UP).toString();
				l1[4] = helper.filterNullValue(kst.getChainRatio()).setScale(2, BigDecimal.ROUND_HALF_UP).toString();
			}
			if (KpiValueConst.KPI0030.equals(kst.getKpiCode())) {
				l2[1] = helper.yuanToTenThousands(kst.getKpiValue()).toString();
				BigDecimal treatFee = kst.getKpiValue();
				fee.put("treatFee", treatFee);
				exactTreatFee[1] = treatFee.toString();
				fee.put("kpi0030Value", new BigDecimal(l2[1]));
				l2[3] = helper.filterNullValue(kst.getPeriodRatio()).setScale(2, BigDecimal.ROUND_HALF_UP).toString();
				l2[4] = helper.filterNullValue(kst.getChainRatio()).setScale(2, BigDecimal.ROUND_HALF_UP).toString();
			}
			if (KpiValueConst.KPI0025.equals(kst.getKpiCode())) {
				l3[1] = helper.yuanToTenThousands(kst.getKpiValue()).toString();
				BigDecimal operationFee = kst.getKpiValue();
				fee.put("operationFee", operationFee);
				exactOperationFee[1] = operationFee.toString();
				fee.put("kpi0025Value", new BigDecimal(l3[1]));
				l3[3] = helper.filterNullValue(kst.getPeriodRatio()).setScale(2, BigDecimal.ROUND_HALF_UP).toString();
				l3[4] = helper.filterNullValue(kst.getChainRatio()).setScale(2, BigDecimal.ROUND_HALF_UP).toString();
			}
			if (KpiValueConst.KPI0032.equals(kst.getKpiCode())) {
				l4[1] = helper.yuanToTenThousands(kst.getKpiValue()).toString();
				BigDecimal assayFee = kst.getKpiValue();
				fee.put("assayFee", assayFee);
				exactAssayFee[1] = assayFee.toString();
				fee.put("kpi0032Value", new BigDecimal(l4[1]));
				l4[3] = helper.filterNullValue(kst.getPeriodRatio()).setScale(2, BigDecimal.ROUND_HALF_UP).toString();
				l4[4] = helper.filterNullValue(kst.getChainRatio()).setScale(2, BigDecimal.ROUND_HALF_UP).toString();
			}
			if (KpiValueConst.KPI0035.equals(kst.getKpiCode())) {
				l5[1] = helper.yuanToTenThousands(kst.getKpiValue()).toString();
				BigDecimal othersFee = kst.getKpiValue();
				fee.put("othersFee", othersFee);
				exactOthersFee[1] = othersFee.toString();
				fee.put("kpi0035Value", new BigDecimal(l5[1]));
				l5[3] = helper.filterNullValue(kst.getPeriodRatio()).setScale(2, BigDecimal.ROUND_HALF_UP).toString();
				l5[4] = helper.filterNullValue(kst.getChainRatio()).setScale(2, BigDecimal.ROUND_HALF_UP).toString();
			}
			if (KpiValueConst.KPI0069.equals(kst.getKpiCode())) {
				l6[1] = helper.yuanToTenThousands(kst.getKpiValue()).toString();
				BigDecimal theRestFee = kst.getKpiValue();
				fee.put("theRestFee", theRestFee);
				exactTheRestFee[1] = theRestFee.toString();
				fee.put("kpi0069Value", new BigDecimal(l6[1]));
				l6[3] = helper.filterNullValue(kst.getPeriodRatio()).setScale(2, BigDecimal.ROUND_HALF_UP).toString();
				l6[4] = helper.filterNullValue(kst.getChainRatio()).setScale(2, BigDecimal.ROUND_HALF_UP).toString();
			}
		}
		kpiFeeList.add(exactCheckFee);
		kpiFeeList.add(exactTreatFee);
		kpiFeeList.add(exactOperationFee);
		kpiFeeList.add(exactAssayFee);
		kpiFeeList.add(exactOthersFee);
		kpiFeeList.add(exactTheRestFee);
		resultMap.put("k2_3_2_2_fee_pieList_end", kpiFeeList);
		BigDecimal exactTotalFee = helper.filterNullValue(fee.get("checkFee"))
				.add(helper.filterNullValue(fee.get("treatFee"))).add(helper.filterNullValue(fee.get("operationFee")))
				.add(helper.filterNullValue(fee.get("assayFee"))).add(helper.filterNullValue(fee.get("othersFee")))
				.add(helper.filterNullValue(fee.get("theRestFee")));
		BigDecimal total = helper.filterNullValue(fee.get("kpi0029Value"))
				.add(helper.filterNullValue(fee.get("kpi0025Value")))
				.add(helper.filterNullValue(fee.get("kpi0030Value")))
				.add(helper.filterNullValue(fee.get("kpi0032Value")))
				.add(helper.filterNullValue(fee.get("kpi0035Value")))
				.add(helper.filterNullValue(fee.get("kpi0069Value"))).setScale(2, BigDecimal.ROUND_HALF_UP);
		l7[1] = total.toString();
		BigDecimal checkPercent = divideNotNullOrZero(fee.get("checkFee"), exactTotalFee).multiply(new BigDecimal(100))
				.setScale(2, BigDecimal.ROUND_HALF_UP);
		l1[2] = checkPercent.toString();
		BigDecimal treatPercent = divideNotNullOrZero(fee.get("treatFee"), exactTotalFee).multiply(new BigDecimal(100))
				.setScale(2, BigDecimal.ROUND_HALF_UP);
		l2[2] = treatPercent.toString();
		BigDecimal operationPercent = divideNotNullOrZero(fee.get("operationFee"), exactTotalFee).multiply(
				new BigDecimal(100)).setScale(2, BigDecimal.ROUND_HALF_UP);
		l3[2] = operationPercent.toString();
		BigDecimal assayPercent = divideNotNullOrZero(fee.get("assayFee"), exactTotalFee).multiply(new BigDecimal(100))
				.setScale(2, BigDecimal.ROUND_HALF_UP);
		l4[2] = assayPercent.toString();
		BigDecimal exactPercent = divideNotNullOrZero(fee.get("othersFee"), exactTotalFee)
				.multiply(new BigDecimal(100)).setScale(2, BigDecimal.ROUND_HALF_UP);
		l5[2] = exactPercent.toString();
		BigDecimal theRestPercent = divideNotNullOrZero(fee.get("theRestFee"), exactTotalFee).multiply(
				new BigDecimal(100)).setScale(2, BigDecimal.ROUND_HALF_UP);
		l6[2] = theRestPercent.toString();
		l7[2] = "100.00";
		kpiList.add(l1);
		kpiList.add(l2);
		kpiList.add(l3);
		kpiList.add(l4);
		kpiList.add(l5);
		kpiList.add(l6);
		kpiList.add(l7);
		resultMap.put("k2_3_2_2_fee_tableList_end", kpiList);
		return resultMap;
	}

	private Map<String, Object> getOutOthersMedDatesByOrg(Map<String, Object> paramsMap,
			Map<String, Object> kpiLimitValue, Map<String, Object> resultMap) {
		String month = paramsMap.get("currentDate").toString();
		String visitType = paramsMap.get("visitType").toString();
		String regionCode = paramsMap.get("regionCode").toString();
		String orgCode = paramsMap.get("medicalOrgCode").toString();

		KpiConditionDTO c = new KpiConditionDTO();
		c.setSociationCode(regionCode);
		c.setOrgCode(orgCode);
		List<String> vl = new ArrayList<String>();
		vl.add(KpiValueConst.VISIT_OUT);
		c.setVisitTypeList(vl);
		List<String> kl = new ArrayList<String>();
		kl.add(KpiValueConst.KPI0070);
		c.setKpiCodeList(kl);
		c.setPeriod(KpiValueConst.MONTH);
		c.setKpiTime(month);
		List<KpiMedicalOrgDTO> list = kpiCoreDataService.queryKpiByOrg(c);
		if (list.isEmpty()) {
			resultMap.put("k2_3_2_2_fee_end", "0.00");
			resultMap.put(
					"k2_3_2_2_fee_health_flag_end",
					helper.checkFlag(helper.checkRation(new BigDecimal(0), new BigDecimal(0),
							setRatioMap("KPI0070", kpiLimitValue))));
			resultMap.put("k2_3_2_2_yoy_flag_end", getAllRatioCompareResult(new BigDecimal(0)));
			resultMap.put("k2_3_2_2_yoy_end", "0.00");
			resultMap.put("k2_3_2_2_yoy_result_end", helper.checkFlag(helper.checkOneRation(new BigDecimal(0),
					setRatioMap("KPI0070", kpiLimitValue), 1)));
			resultMap.put("k2_3_2_2_mom_flag_end", getAllRatioCompareResult(new BigDecimal(0)));
			resultMap.put("k2_3_2_2_mom_end", "0.00");
			resultMap.put("k2_3_2_2_mom_result_end", helper.checkFlag(helper.checkOneRation(new BigDecimal(0),
					setRatioMap("KPI0070", kpiLimitValue), 2)));
			helper.setRatioYoyAndMom(resultMap, kpiLimitValue, "KPI0069", KpiValueConst.KPI0070);
		} else {
			resultMap = conventOutOthersFeeListByOrg(resultMap, list, month, visitType, kpiLimitValue);
		}
		return resultMap;
	}

	private Map<String, Object> conventOutOthersFeeListByOrg(Map<String, Object> resultMap,
			List<KpiMedicalOrgDTO> list, String month, String visitType, Map<String, Object> kpiLimitValue) {
		for (KpiMedicalOrgDTO ksd : list) {
			if (KpiValueConst.KPI0070.equals(ksd.getKpiCode())) {
				resultMap.put("k2_3_2_2_fee_end",
						twoDecimals(helper.yuanToTenThousands(helper.filterNullValue(ksd.getKpiValue()))));
				resultMap.put(
						"k2_3_2_2_fee_health_flag_end",
						helper.checkRation(helper.filterNullValue(ksd.getPeriodRatio()),
								helper.filterNullValue(ksd.getChainRatio()), setRatioMap("KPI0070", kpiLimitValue)));
				resultMap.put("k2_3_2_2_fee_cookie_end", helper.filterNullValue(ksd.getKpiValue()));
				resultMap.put("k2_3_2_2_yoy_end", twoDecimals(helper.filterNullValue(ksd.getPeriodRatio())).abs());
				resultMap.put("k2_3_2_2_yoy_flag_end",
						getAllRatioCompareResult(helper.filterNullValue(ksd.getPeriodRatio())));
				resultMap.put("k2_3_2_2_yoy_result_end", helper.checkFlag(helper.checkOneRation(
						helper.filterNullValue(ksd.getPeriodRatio()), setRatioMap("KPI0070", kpiLimitValue), 1)));
				resultMap.put("k2_3_2_2_mom_end", twoDecimals(helper.filterNullValue(ksd.getChainRatio())).abs());
				resultMap.put("k2_3_2_2_mom_flag_end",
						getAllRatioCompareResult(helper.filterNullValue(ksd.getChainRatio())));
				resultMap.put("k2_3_2_2_mom_result_end", helper.checkFlag(helper.checkOneRation(
						helper.filterNullValue(ksd.getChainRatio()), setRatioMap("KPI0070", kpiLimitValue), 2)));
			}
		}
		return helper.setRatioYoyAndMom(resultMap, kpiLimitValue, "KPI0069", KpiValueConst.KPI0070);
	}

	private Map<String, Object> getOutCheckKpiInfoByOrg(Map<String, Object> paramsMap, Map<String, Object> resultMap) {
		paramsMap.put("visitType", KpiValueConst.VISIT_OUT);
		GeneralMethods.getInstance().addAllValueToMap(getOutCheckKpiByOrg(paramsMap), resultMap);
		return resultMap;
	}

	private Map<String, Object> getOutCheckKpiByOrg(Map<String, Object> paramsMap) {
		String endMonth = paramsMap.get("currentDate").toString();
		String visitType = paramsMap.get("visitType").toString();
		String regionCode = paramsMap.get("regionCode").toString();
		Map<String, Object> resultMap = new HashMap<String, Object>();
		KpiConditionDTO c = new KpiConditionDTO();
		c.setSociationCode(regionCode);
		List<String> vl = new ArrayList<String>();
		vl.add(KpiValueConst.VISIT_OUT);
		c.setVisitTypeList(vl);
		List<String> kl = new ArrayList<String>();
		c.setOrgCode(paramsMap.get("medicalOrgCode").toString());
		c.setKpiCodeList(kl);
		c.setPeriod(KpiValueConst.MONTH);
		String startMonth = helper.getStartDate(endMonth, -Constant.MONTH_THIRTYFIVE);
		c.setKpiTimeStart(startMonth);
		c.setKpiTimeEnd(endMonth);
		kl.add(KpiValueConst.KPI0025);
		List<KpiMedicalOrgDTO> dataList = kpiCoreDataService.queryKpiByOrg(c);
		resultMap = conventOutCheckOrgListToMap(KpiValueConst.KPI0025, dataList, startMonth, endMonth, visitType,
				resultMap);
		kl.clear();
		kl.add(KpiValueConst.KPI0029);
		List<KpiMedicalOrgDTO> dataList1 = kpiCoreDataService.queryKpiByOrg(c);
		resultMap = conventOutCheckOrgListToMap(KpiValueConst.KPI0029, dataList1, startMonth, endMonth, visitType,
				resultMap);
		kl.clear();
		kl.add(KpiValueConst.KPI0030);
		List<KpiMedicalOrgDTO> dataList2 = kpiCoreDataService.queryKpiByOrg(c);
		resultMap = conventOutCheckOrgListToMap(KpiValueConst.KPI0030, dataList2, startMonth, endMonth, visitType,
				resultMap);
		kl.clear();
		kl.add(KpiValueConst.KPI0032);
		List<KpiMedicalOrgDTO> dataList3 = kpiCoreDataService.queryKpiByOrg(c);
		resultMap = conventOutCheckOrgListToMap(KpiValueConst.KPI0032, dataList3, startMonth, endMonth, visitType,
				resultMap);
		kl.clear();
		kl.add(KpiValueConst.KPI0035);
		List<KpiMedicalOrgDTO> dataList4 = kpiCoreDataService.queryKpiByOrg(c);
		resultMap = conventOutCheckOrgListToMap(KpiValueConst.KPI0035, dataList4, startMonth, endMonth, visitType,
				resultMap);
		kl.clear();
		kl.add(KpiValueConst.KPI0069);
		List<KpiMedicalOrgDTO> dataList5 = kpiCoreDataService.queryKpiByOrg(c);
		resultMap = conventOutCheckOrgListToMap(KpiValueConst.KPI0069, dataList5, startMonth, endMonth, visitType,
				resultMap);
		return resultMap;
	}

	@SuppressWarnings("unchecked")
	private Map<String, Object> conventOutCheckOrgListToMap(String kpiCode, List<KpiMedicalOrgDTO> dataList,
			String startMonth, String endMonth, String visitType, Map<String, Object> resultMap) {
		Map<String, Object> dataMap = getCheckCalculateOrgDataMap(kpiCode, dataList, visitType, startMonth, endMonth);
		// // 将查询数据封装到List
		List<BigDecimal> periodList = (List<BigDecimal>) dataMap.get("periodList_end");
		List<BigDecimal> chainList = (List<BigDecimal>) dataMap.get("chainList_end");
		// // 总额
		List<BigDecimal> totalList = (List<BigDecimal>) dataMap.get("totalList_end");

		Map<String, Object> avgDataMap = getAvgData(periodList, chainList, totalList);

		// // 同期平均值计算
		List<BigDecimal> avgList = (List<BigDecimal>) avgDataMap.get("avgList");
		List<BigDecimal> RecentOneYear = helper.createSetListValue(Constant.MONTH_TWELVE, new BigDecimal(0));
		List<BigDecimal> periodLine = helper.createSetListValue(Constant.MONTH_TWELVE, new BigDecimal(0));
		List<BigDecimal> chainLine = helper.createSetListValue(Constant.MONTH_TWELVE, new BigDecimal(0));
		for (int i = 0; i < Constant.MONTH_TWELVE; i++) {
			RecentOneYear.set(i, helper.filterNullValue(totalList.get(totalList.size() + i - Constant.MONTH_TWELVE)));
			periodLine.set(i, helper.filterNullValue(periodList.get(periodList.size() + i - Constant.MONTH_TWELVE)));
			chainLine.set(i, helper.filterNullValue(chainList.get(chainList.size() + i - Constant.MONTH_TWELVE)));
		}
		if (KpiValueConst.KPI0025.equals(kpiCode)) {
			resultMap.put("k2_3_2_25_fee_gqynList_end", helper.toFixedUniqueOrgList(RecentOneYear));
			resultMap.put("k2_3_2_25_fee_gqsnList_end", helper.toFixedUniqueOrgList(avgList));
			resultMap.put("k2_3_2_25_fee_yoyList_end", helper.toFixedPercentList(periodLine));
			resultMap.put("k2_3_2_25_fee_momList_end", helper.toFixedPercentList(chainLine));
		}
		if (KpiValueConst.KPI0029.equals(kpiCode)) {
			resultMap.put("k2_3_2_2_fee_gqynList_end", helper.toFixedUniqueOrgList(RecentOneYear));
			resultMap.put("k2_3_2_2_fee_gqsnList_end", helper.toFixedUniqueOrgList(avgList));
			resultMap.put("k2_3_2_2_fee_yoyList_end", helper.toFixedPercentList(periodLine));
			resultMap.put("k2_3_2_2_fee_momList_end", helper.toFixedPercentList(chainLine));
		}
		if (KpiValueConst.KPI0030.equals(kpiCode)) {
			resultMap.put("k2_3_2_30_fee_gqynList_end", helper.toFixedUniqueOrgList(RecentOneYear));
			resultMap.put("k2_3_2_30_fee_gqsnList_end", helper.toFixedUniqueOrgList(avgList));
			resultMap.put("k2_3_2_30_fee_yoyList_end", helper.toFixedPercentList(periodLine));
			resultMap.put("k2_3_2_30_fee_momList_end", helper.toFixedPercentList(chainLine));
		}
		if (KpiValueConst.KPI0032.equals(kpiCode)) {
			resultMap.put("k2_3_2_32_fee_gqynList_end", helper.toFixedUniqueOrgList(RecentOneYear));
			resultMap.put("k2_3_2_32_fee_gqsnList_end", helper.toFixedUniqueOrgList(avgList));
			resultMap.put("k2_3_2_32_fee_yoyList_end", helper.toFixedPercentList(periodLine));
			resultMap.put("k2_3_2_32_fee_momList_end", helper.toFixedPercentList(chainLine));
		}
		if (KpiValueConst.KPI0035.equals(kpiCode)) {
			resultMap.put("k2_3_2_35_fee_gqynList_end", helper.toFixedUniqueOrgList(RecentOneYear));
			resultMap.put("k2_3_2_35_fee_gqsnList_end", helper.toFixedUniqueOrgList(avgList));
			resultMap.put("k2_3_2_35_fee_yoyList_end", helper.toFixedPercentList(periodLine));
			resultMap.put("k2_3_2_35_fee_momList_end", helper.toFixedPercentList(chainLine));
		}
		if (KpiValueConst.KPI0069.equals(kpiCode)) {
			resultMap.put("k2_3_2_69_fee_gqynList_end", helper.toFixedUniqueOrgList(RecentOneYear));
			resultMap.put("k2_3_2_69_fee_gqsnList_end", helper.toFixedUniqueOrgList(avgList));
			resultMap.put("k2_3_2_69_fee_yoyList_end", helper.toFixedPercentList(periodLine));
			resultMap.put("k2_3_2_69_fee_momList_end", helper.toFixedPercentList(chainLine));
		}
		return resultMap;
	}

	private Map<String, Object> getCheckCalculateOrgDataMap(String kpiCode, List<KpiMedicalOrgDTO> dataList,
			String visitType, String startMonth, String endMonth) {
		Map<String, Object> CalculateDataMap = new HashMap<String, Object>();
		String kpiTime = "";
		BigDecimal kpiValue = null;
		BigDecimal periodRatio = null;// 同比
		BigDecimal chainRatio = null;// 环比
		// // 将查询数据封装到List
		Map<String, Integer> orderMap = helper.createOrderList(startMonth, endMonth);
		List<BigDecimal> periodList = helper.createSetListValue(orderMap.size(), new BigDecimal(0));
		List<BigDecimal> chainList = helper.createSetListValue(orderMap.size(), new BigDecimal(0));
		// // 总额
		List<BigDecimal> totalList = helper.createSetListValue(orderMap.size(), new BigDecimal(0));

		for (KpiMedicalOrgDTO kpiMedicalOrgDTO : dataList) {
			kpiCode = kpiMedicalOrgDTO.getKpiCode();
			kpiValue = kpiMedicalOrgDTO.getKpiValue();
			periodRatio = kpiMedicalOrgDTO.getPeriodRatio();
			chainRatio = kpiMedicalOrgDTO.getChainRatio();
			kpiTime = GeneralMethods.getInstance().replacTimeFormate(kpiMedicalOrgDTO.getKpiTime());
			if (KpiValueConst.KPI0025.equals(kpiCode)) {
				if (kpiMedicalOrgDTO.getVisitType().equals(visitType)) {
					periodList.set(orderMap.get(kpiTime), helper.filterNullValue(periodRatio));
					chainList.set(orderMap.get(kpiTime), helper.filterNullValue(chainRatio));
					totalList.set(orderMap.get(kpiTime), helper.filterNullValue(kpiValue));
				}
			}
			if (KpiValueConst.KPI0029.equals(kpiCode)) {
				if (kpiMedicalOrgDTO.getVisitType().equals(visitType)) {
					periodList.set(orderMap.get(kpiTime), helper.filterNullValue(periodRatio));
					chainList.set(orderMap.get(kpiTime), helper.filterNullValue(chainRatio));
					totalList.set(orderMap.get(kpiTime), helper.filterNullValue(kpiValue));
				}
			}
			if (KpiValueConst.KPI0030.equals(kpiCode)) {
				if (kpiMedicalOrgDTO.getVisitType().equals(visitType)) {
					periodList.set(orderMap.get(kpiTime), helper.filterNullValue(periodRatio));
					chainList.set(orderMap.get(kpiTime), helper.filterNullValue(chainRatio));
					totalList.set(orderMap.get(kpiTime), helper.filterNullValue(kpiValue));
				}
			}
			if (KpiValueConst.KPI0032.equals(kpiCode)) {
				if (kpiMedicalOrgDTO.getVisitType().equals(visitType)) {
					periodList.set(orderMap.get(kpiTime), helper.filterNullValue(periodRatio));
					chainList.set(orderMap.get(kpiTime), helper.filterNullValue(chainRatio));
					totalList.set(orderMap.get(kpiTime), helper.filterNullValue(kpiValue));
				}
			}
			if (KpiValueConst.KPI0035.equals(kpiCode)) {
				if (kpiMedicalOrgDTO.getVisitType().equals(visitType)) {
					periodList.set(orderMap.get(kpiTime), helper.filterNullValue(periodRatio));
					chainList.set(orderMap.get(kpiTime), helper.filterNullValue(chainRatio));
					totalList.set(orderMap.get(kpiTime), helper.filterNullValue(kpiValue));
				}
			}
			if (KpiValueConst.KPI0069.equals(kpiCode)) {
				if (kpiMedicalOrgDTO.getVisitType().equals(visitType)) {
					periodList.set(orderMap.get(kpiTime), helper.filterNullValue(periodRatio));
					chainList.set(orderMap.get(kpiTime), helper.filterNullValue(chainRatio));
					totalList.set(orderMap.get(kpiTime), helper.filterNullValue(kpiValue));
				}
			}
		}
		CalculateDataMap.put("orderMap", orderMap);
		CalculateDataMap.put("periodList_end", periodList);
		CalculateDataMap.put("chainList_end", chainList);
		CalculateDataMap.put("totalList_end", totalList);
		return CalculateDataMap;
	}

	private String getAllRatioCompareResult(BigDecimal toCompareList) {
		String message = "";
		if (toCompareList.compareTo(new BigDecimal(0)) >= 0) {
			message = "增加";
		}
		if (toCompareList.compareTo(new BigDecimal(0)) < 0) {
			message = "降低";
		}
		return message;
	}

	private Map<String, Object> setRatioMap(String kpiCode, Map<String, Object> kpiLimitValue) {
		Map<String, Object> ratioMap = new HashMap<String, Object>();
		ratioMap.put("yoy_upper", kpiLimitValue.get(kpiCode + "_yoy_upper_end"));
		ratioMap.put("yoy_lower", kpiLimitValue.get(kpiCode + "_yoy_lower_end"));
		ratioMap.put("mom_upper", kpiLimitValue.get(kpiCode + "_mom_upper_end"));
		ratioMap.put("mom_lower", kpiLimitValue.get(kpiCode + "_mom_lower_end"));

		return ratioMap;
	}

	private KpiConditionDTO getKpiConditionByKpiCode(Map<String, Object> paramsMap, String kpiCode) {
		String visitType = (String) paramsMap.get("visitType");
		String month = (String) paramsMap.get("currentDate");
		String regionCode = (String) paramsMap.get("regionCode");
		KpiConditionDTO con = new KpiConditionDTO();
		con.setVisitType(visitType);
		con.setKpiCode(kpiCode);
		con.setKpiTime(month);
		con.setPeriod(Constants.perion_13);
		con.setSociationCode(regionCode);
		return con;
	}

}
